From 1f43d039e02abe234fbbfdc0f213c57f1957ea35 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sun, 5 May 2019 01:24:31 -0500 Subject: [PATCH] updates to files --- app/Jobs/ProcessWalletJournalJob.php | 22 +++- app/Jobs/ProcessWallettransactionJob.php | 22 +++- app/Jobs/SendEveMail.php | 118 ------------------ app/Jobs/SendEveMailJob.php | 30 ++++- app/Library/Esi/Esi.php | 10 +- app/Library/Finances/Helper/FinanceHelper.php | 10 +- app/Library/Moons/MoonMailer.php | 8 +- app/Models/Jobs/JobError.php | 29 +++++ app/Models/Jobs/JobStatus.php | 29 +++++ ..._05_035513_create_completed_jobs_table.php | 32 ----- ..._05_05_044159_create_jobs_status_table.php | 45 +++++++ vendor/composer/autoload_classmap.php | 4 +- vendor/composer/autoload_static.php | 4 +- 13 files changed, 194 insertions(+), 169 deletions(-) delete mode 100644 app/Jobs/SendEveMail.php create mode 100644 app/Models/Jobs/JobError.php create mode 100644 app/Models/Jobs/JobStatus.php delete mode 100644 database/migrations/2019_05_05_035513_create_completed_jobs_table.php create mode 100644 database/migrations/2019_05_05_044159_create_jobs_status_table.php diff --git a/app/Jobs/ProcessWalletJournalJob.php b/app/Jobs/ProcessWalletJournalJob.php index 409706585..9cf89da53 100644 --- a/app/Jobs/ProcessWalletJournalJob.php +++ b/app/Jobs/ProcessWalletJournalJob.php @@ -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(); } } diff --git a/app/Jobs/ProcessWallettransactionJob.php b/app/Jobs/ProcessWallettransactionJob.php index 4e0bcf28d..ad617595f 100644 --- a/app/Jobs/ProcessWallettransactionJob.php +++ b/app/Jobs/ProcessWallettransactionJob.php @@ -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(); } } diff --git a/app/Jobs/SendEveMail.php b/app/Jobs/SendEveMail.php deleted file mode 100644 index d3e2fd350..000000000 --- a/app/Jobs/SendEveMail.php +++ /dev/null @@ -1,118 +0,0 @@ -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); - } -} diff --git a/app/Jobs/SendEveMailJob.php b/app/Jobs/SendEveMailJob.php index 1804901d3..dffff0318 100644 --- a/app/Jobs/SendEveMailJob.php +++ b/app/Jobs/SendEveMailJob.php @@ -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(); } } diff --git a/app/Library/Esi/Esi.php b/app/Library/Esi/Esi.php index c4bde463e..57c82207a 100644 --- a/app/Library/Esi/Esi.php +++ b/app/Library/Esi/Esi.php @@ -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; } diff --git a/app/Library/Finances/Helper/FinanceHelper.php b/app/Library/Finances/Helper/FinanceHelper.php index 195d97843..ec3342cc2 100644 --- a/app/Library/Finances/Helper/FinanceHelper.php +++ b/app/Library/Finances/Helper/FinanceHelper.php @@ -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; } diff --git a/app/Library/Moons/MoonMailer.php b/app/Library/Moons/MoonMailer.php index c42232755..3ee6f90f5 100644 --- a/app/Library/Moons/MoonMailer.php +++ b/app/Library/Moons/MoonMailer.php @@ -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); } } diff --git a/app/Models/Jobs/JobError.php b/app/Models/Jobs/JobError.php new file mode 100644 index 000000000..b6076e484 --- /dev/null +++ b/app/Models/Jobs/JobError.php @@ -0,0 +1,29 @@ +belongsTo('\App\Models\Jobs\JobStatus'); + } +} diff --git a/app/Models/Jobs/JobStatus.php b/app/Models/Jobs/JobStatus.php new file mode 100644 index 000000000..52738c7be --- /dev/null +++ b/app/Models/Jobs/JobStatus.php @@ -0,0 +1,29 @@ +hasOne('\App\Models\Jobs\JobError', 'job_id', 'id'); + } +} diff --git a/database/migrations/2019_05_05_035513_create_completed_jobs_table.php b/database/migrations/2019_05_05_035513_create_completed_jobs_table.php deleted file mode 100644 index 6a45ce346..000000000 --- a/database/migrations/2019_05_05_035513_create_completed_jobs_table.php +++ /dev/null @@ -1,32 +0,0 @@ -increments('id'); - - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('completed_jobs'); - } -} diff --git a/database/migrations/2019_05_05_044159_create_jobs_status_table.php b/database/migrations/2019_05_05_044159_create_jobs_status_table.php new file mode 100644 index 000000000..e68b75f61 --- /dev/null +++ b/database/migrations/2019_05_05_044159_create_jobs_status_table.php @@ -0,0 +1,45 @@ +increments('id'); + $table->string('job_name'); + $table->boolean('complete')->default(false); + $table->timestamps(); + }); + } + + if(!Schema::hasTable('jobs_errors')) { + Schema::create('jobs_errors', function(Blueprint $table) { + $table->integer('job_id'); + $table->string('job_name'); + $table->text('error'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('jobs_status'); + Schema::dropIfExists('jobs_errors'); + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index e153d7d29..109512a6b 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -39,9 +39,8 @@ return array( 'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => $baseDir . '/app/Http/Middleware/VerifyCsrfToken.php', - 'App\\JobProcessWalletTransaction' => $baseDir . '/app/Models/Jobs/JobProcessWalletTransaction.php', 'App\\Jobs\\ProcessWalletJournalJob' => $baseDir . '/app/Jobs/ProcessWalletJournalJob.php', - 'App\\Jobs\\ProcessWallettransactionJob' => $baseDir . '/app/Jobs/ProcessWallettransactionJob.php', + 'App\\Jobs\\ProcessWalletTransactionJob' => $baseDir . '/app/Jobs/ProcessWalletTransactionJob.php', 'App\\Jobs\\SendEveMail' => $baseDir . '/app/Jobs/SendEveMail.php', 'App\\Jobs\\SendEveMailJob' => $baseDir . '/app/Jobs/SendEveMailJob.php', 'App\\Library\\Esi\\Esi' => $baseDir . '/app/Library/Esi/Esi.php', @@ -87,6 +86,7 @@ return array( 'App\\Models\\Fleet\\Fleet' => $baseDir . '/app/Models/Fleet/Fleet.php', 'App\\Models\\Fleet\\FleetActivity' => $baseDir . '/app/Models/Fleet/FleetActivity.php', 'App\\Models\\Jobs\\JobProcessWalletJournal' => $baseDir . '/app/Models/Jobs/JobProcessWalletJournal.php', + 'App\\Models\\Jobs\\JobProcessWalletTransaction' => $baseDir . '/app/Models/Jobs/JobProcessWalletTransaction.php', 'App\\Models\\Jobs\\JobSendEveMail' => $baseDir . '/app/Models/Jobs/JobSendEveMail.php', 'App\\Models\\Lookups\\CharacterToCorporation' => $baseDir . '/app/Models/Lookups/CharacterToCorporation.php', 'App\\Models\\Lookups\\CorporationToAlliance' => $baseDir . '/app/Models/Lookups/CorporationToAlliance.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index bdd7287d4..33eb7e8c3 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -493,9 +493,8 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => __DIR__ . '/../..' . '/app/Http/Middleware/VerifyCsrfToken.php', - 'App\\JobProcessWalletTransaction' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessWalletTransaction.php', 'App\\Jobs\\ProcessWalletJournalJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessWalletJournalJob.php', - 'App\\Jobs\\ProcessWallettransactionJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessWallettransactionJob.php', + 'App\\Jobs\\ProcessWalletTransactionJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessWalletTransactionJob.php', 'App\\Jobs\\SendEveMail' => __DIR__ . '/../..' . '/app/Jobs/SendEveMail.php', 'App\\Jobs\\SendEveMailJob' => __DIR__ . '/../..' . '/app/Jobs/SendEveMailJob.php', 'App\\Library\\Esi\\Esi' => __DIR__ . '/../..' . '/app/Library/Esi/Esi.php', @@ -541,6 +540,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Models\\Fleet\\Fleet' => __DIR__ . '/../..' . '/app/Models/Fleet/Fleet.php', 'App\\Models\\Fleet\\FleetActivity' => __DIR__ . '/../..' . '/app/Models/Fleet/FleetActivity.php', 'App\\Models\\Jobs\\JobProcessWalletJournal' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessWalletJournal.php', + 'App\\Models\\Jobs\\JobProcessWalletTransaction' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessWalletTransaction.php', 'App\\Models\\Jobs\\JobSendEveMail' => __DIR__ . '/../..' . '/app/Models/Jobs/JobSendEveMail.php', 'App\\Models\\Lookups\\CharacterToCorporation' => __DIR__ . '/../..' . '/app/Models/Lookups/CharacterToCorporation.php', 'App\\Models\\Lookups\\CorporationToAlliance' => __DIR__ . '/../..' . '/app/Models/Lookups/CorporationToAlliance.php',