updates to files

This commit is contained in:
2019-05-05 01:24:31 -05:00
parent c752f5679f
commit 1f43d039e0
13 changed files with 194 additions and 169 deletions
+20 -2
View File
@@ -14,6 +14,8 @@ use App\Library\Finances\Helper\FinanceHelper;
//App Models
use App\Models\Jobs\JobProcessWalletJournal;
use App\Models\Jobs\JobError;
use App\Models\Jobs\JobStatus;
class ProcessWalletJournalJob implements ShouldQueue
{
@@ -63,6 +65,12 @@ class ProcessWalletJournalJob implements ShouldQueue
//After the job is completed, delete the job
$this->delete();
//If the job is completed, mark down the completed job in the status table for jobs
$job = new JobStatus;
$job->job_name = $this->getName();
$job->complete = true;
$job->save();
}
/**
@@ -73,7 +81,17 @@ class ProcessWalletJournalJob implements ShouldQueue
*/
public function failed($exception)
{
// Send user notification of failure, etc...
dd($exception);
//Save the error in the database
$job = new JobStatus;
$job->job_name = $this->getName();
$job->complete = false;
$job->save();
//Save the job error
$error = new JobError;
$error->job_id = $job->id;
$error->job_name = $this->getName();
$error->error = $exception;
$error->save();
}
}
+20 -2
View File
@@ -14,6 +14,8 @@ use App\Library\Finances\Helper\FinanceHelper;
//App Models
use App\Models\Jobs\JobProcessWalletTransaction;
use App\Models\Jobs\JobError;
use App\Models\Jobs\JobStatus;
class ProcessWalletTransactionJob implements ShouldQueue
{
@@ -61,6 +63,12 @@ class ProcessWalletTransactionJob implements ShouldQueue
//After the job is completed, delete the job
$this->delete();
//If the job is completed, mark down the completed job in the status table for jobs
$job = new JobStatus;
$job->job_name = $this->getName();
$job->complete = true;
$job->save();
}
/**
@@ -70,7 +78,17 @@ class ProcessWalletTransactionJob implements ShouldQueue
* @return void
*/
public function failed($exception) {
// Send user notification of the failure, etc.
dd($exception);
//Save the error in the database
$job = new JobStatus;
$job->job_name = $this->getName();
$job->complete = false;
$job->save();
//Save the job error
$error = new JobError;
$error->job_id = $job->id;
$error->job_name = $this->getName();
$error->error = $exception;
$error->save();
}
}
-118
View File
@@ -1,118 +0,0 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken;
use App\Models\Mail\EveMail;
class SendEveMail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Class Variable for eve mail
*/
protected $eveMail;
/**
* Timeout in seconds
*
* @var int
*/
public $timeout = 120;
/**
* Retries
*
* @var int
*/
public $retries = 3;
private $body;
private $recipient;
private $recipient_type;
private $subject;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(EveMail $mail) {
$this->body = $mail->body;
$this->recipient = $mail->recipient;
$this->recipient_type = $mail->recipient_type;
$this->subject = $mail->subject;
$this->connection = 'database';
}
/**
* Execute the job.
* Utilized by using SendEveMail::dispatch($mail);
* The model is passed into the dispatch function, then added to the queue
* for processing.
*
* @return void
*/
public function handle()
{
//Retrieve the token for main character to send mails from
$token = EsiToken::where(['character_id'=> 93738489])->get();
//Create the ESI authentication container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
//Setup the Eseye class
$esi = new Eseye($authentication);
//Attemp to send the mail
try {
$esi->setBody([
'approved_cost' => 0,
'body' => $this->body,
'recipients' => [[
'recipient_id' => (int)$this->recipient,
'recipient_type' => $this->recipient_type,
]],
'subject' => $this->subject,
])->invoke('post', '/characters/{character_id}/mail/', [
'character_id'=> 93738489,
]);
} catch(RequestFailedException $e) {
return null;
}
$this->eveMail->delete();
}
/**
* The job failed to process.
*
* @param Exception $exception
* @return void
*/
public function failed($exception)
{
// Send user notification of failure, etc...
dd($exception);
}
}
+25 -5
View File
@@ -2,21 +2,25 @@
namespace App\Jobs;
//Internal Library
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
//Seat stuff
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
//Models
use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken;
use App\Models\Mail\EveMail;
use App\Models\Jobs\JobError;
use App\Models\Jobs\JobStatus;
class SendEveMailJob implements ShouldQueue
{
@@ -57,7 +61,7 @@ class SendEveMailJob implements ShouldQueue
/**
* Execute the job.
* Utilized by using SendEveMail::dispatch($mail);
* Utilized by using SendEveMailJob::dispatch($mail);
* The model is passed into the dispatch function, then added to the queue
* for processing.
*
@@ -96,7 +100,13 @@ class SendEveMailJob implements ShouldQueue
return null;
}
$this->eveMail->delete();
$this->delete();
//If the job is completed, mark down the completed job in the status table for jobs
$job = new JobStatus;
$job->job_name = $this->getName();
$job->complete = true;
$job->save();
}
/**
@@ -107,7 +117,17 @@ class SendEveMailJob implements ShouldQueue
*/
public function failed($exception)
{
// Send user notification of failure, etc...
dd($exception);
//Save the error in the database
$job = new JobStatus;
$job->job_name = $this->getName();
$job->complete = false;
$job->save();
//Save the job error
$error = new JobError;
$error->job_id = $job->id;
$error->job_name = $this->getName();
$error->error = $exception;
$error->save();
}
}
+8 -2
View File
@@ -2,11 +2,17 @@
namespace App\Library\Esi;
//Internal Libraries
use DB;
//Models
use App\Models\Esi\EsiScope;
use App\Jobs\SendEveMail;
use App\Models\Jobs\JobSendEveMail;
//Jobs
use App\Jobs\SendEveMailJob;
//Seat Stuff
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
@@ -43,7 +49,7 @@ class Esi {
$mail->recipient_type = 'character';
$mail->save();
SendEveMail::dispatch($mail)->delay(Carbon::now()->addSeconds(5));
SendEveMailJob::dispatch($mail)->delay(Carbon::now()->addSeconds(5));
return false;
}
@@ -7,13 +7,18 @@
namespace App\Library\Finances\Helper;
//Internal Library
use DB;
use App\Jobs\SendEveMail;
//Job
use App\Jobs\SendEveMailJob;
//Models
use App\Models\Esi\EsiToken;
use App\Models\Esi\EsiScope;
use App\Models\Mail\EveMail;
//Library
use App\Library\Esi\Esi;
use App\Library\Finances\MarketTax;
use App\Library\Finances\PlayerDonation;
@@ -25,6 +30,7 @@ use App\Library\Finances\PlanetProductionTax;
use App\Library\Finances\PISale;
use App\Library\Lookups\LookupHelper;
//Seat Stuff
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
@@ -311,7 +317,7 @@ class FinanceHelper {
$mail->recipient_type = 'character';
$mail->save();
SendEveMail::dispatch($mail);
SendEveMailJob::dispatch($mail);
return true;
}
+6 -2
View File
@@ -2,7 +2,11 @@
namespace App\Library\Moons;
use App\Models\Mail\EveMail;
//Jobs
use App\Jobs\SendEveMailJob;
//Models
use App\Models\Jobs\JobSendEveMail;
class MoonMailer {
@@ -26,7 +30,7 @@ class MoonMailer {
$mail->recipient_type = 'character';
$mail->save();
SendEveMail::dispatch($mail);
SendEveMailJob::dispatch($mail);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Models\Jobs;
use Illuminate\Database\Eloquent\Model;
class JobError extends Model
{
//Table Name
public $table = 'job_statuses';
//Timestamps
public $timestaps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'job_id',
'job_name',
'error',
];
public function JobStatus() {
$this->belongsTo('\App\Models\Jobs\JobStatus');
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Models\Jobs;
use Illuminate\Database\Eloquent\Model;
class JobStatus extends Model
{
//Table Name
public $table = 'job_statuses';
//Timestamps
public $timestaps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'id',
'job_name',
'complete',
];
public function Error() {
$this->hasOne('\App\Models\Jobs\JobError', 'job_id', 'id');
}
}