From 98ee6f52069d158ceaed7c348cde08426d8c4aff Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Mon, 13 May 2019 23:18:10 -0500 Subject: [PATCH] job stuff --- app/Console/Commands/Library/helper.php | 2 +- app/Jobs/Library/JobHelper.php | 42 +++++++++++++++++++ app/Jobs/ProcessWalletJournalJob.php | 8 ++-- app/Jobs/ProcessWallettransactionJob.php | 8 ++-- app/Jobs/SendEveMailJob.php | 8 ++-- app/Models/Jobs/JobStatus.php | 1 + ...9_05_05_064022_create_job_status_table.php | 1 + 7 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 app/Jobs/Library/JobHelper.php diff --git a/app/Console/Commands/Library/helper.php b/app/Console/Commands/Library/helper.php index 2c3aad4fd..941699756 100644 --- a/app/Console/Commands/Library/helper.php +++ b/app/Console/Commands/Library/helper.php @@ -41,7 +41,7 @@ class CommandHelper { } public function CleanJobStatusTable() { - DB::table('schedule_jobs')->where('system_time', '<', Carbon::now()->subMonths(6))->delete(); + DB::table('schedule_jobs')->where('system_time', '<', Carbon::now()->subMonths(3))->delete(); } } diff --git a/app/Jobs/Library/JobHelper.php b/app/Jobs/Library/JobHelper.php new file mode 100644 index 000000000..aa3d887aa --- /dev/null +++ b/app/Jobs/Library/JobHelper.php @@ -0,0 +1,42 @@ +job_name = $name; + $this->complete = false; + $this->system_time = Carbon::now(); + } + + public function SetStartStatus() { + $this->jobStatus = new JobStatus; + $this->jobStatus->job_name = $this->job_name; + $this->jobStatus->complete = $this->complete; + $this->jobStatus->system_time = $this->system_time; + + $job->save(); + } + + public function SetStopStatus() { + $this->jobStatus::update([ + 'complete' => true, + ]); + } + + public function CleeanJobStatusTable() { + DB::table('job_statuses')->where('system_time', '<', Carbon::now()->subMonths(3))->delete(); + } +} \ No newline at end of file diff --git a/app/Jobs/ProcessWalletJournalJob.php b/app/Jobs/ProcessWalletJournalJob.php index 20172ad7b..7ee1add26 100644 --- a/app/Jobs/ProcessWalletJournalJob.php +++ b/app/Jobs/ProcessWalletJournalJob.php @@ -57,15 +57,15 @@ class ProcessWalletJournalJob implements ShouldQueue */ public function handle() { + $status = new JobHelper('Process Wallet Journal'); + $status->SetStartStatus(); + //Declare the class variable we need $finance = new FinanceHelper(); $finance->GetWalletJournalPage($this->division, $this->charId, $this->page); - $status = new JobStatus; - $status->job_name = 'Process Wallet Journal'; - $status->complete = true; - $status->save(); + $status->SetStopStatus(); //After the job is completed, delete the job $this->delete(); diff --git a/app/Jobs/ProcessWallettransactionJob.php b/app/Jobs/ProcessWallettransactionJob.php index 4a8e5b0b0..e4455c078 100644 --- a/app/Jobs/ProcessWallettransactionJob.php +++ b/app/Jobs/ProcessWallettransactionJob.php @@ -53,15 +53,15 @@ class ProcessWalletTransactionJob implements ShouldQueue */ public function handle() { + $status = new JobHelper('Process Wallet Transaction'); + $status->SetStartStatus(); + //Declare the class variables $finance = new FinanceHelper(); $finance->GetWalletTransaction($this->division, $this->charId); - $status = new JobStatus; - $status->job_name = 'Process Wallet Transaction'; - $status->complete = true; - $status->save(); + $status->SetStopStatus(); //After the job is completed, delete the job $this->delete(); diff --git a/app/Jobs/SendEveMailJob.php b/app/Jobs/SendEveMailJob.php index 5e225326b..6def9298b 100644 --- a/app/Jobs/SendEveMailJob.php +++ b/app/Jobs/SendEveMailJob.php @@ -69,6 +69,9 @@ class SendEveMailJob implements ShouldQueue */ public function handle() { + $status = new JobHelper('Send EveMail'); + $status->SetStartStatus(); + //Retrieve the token for main character to send mails from $token = EsiToken::where(['character_id'=> 93738489])->get(); @@ -100,10 +103,7 @@ class SendEveMailJob implements ShouldQueue return null; } - $status = new JobStatus; - $status->job_name = 'Send Eve Mail'; - $status->complete = true; - $status->save(); + $status->SetStopStatus(); $this->delete(); } diff --git a/app/Models/Jobs/JobStatus.php b/app/Models/Jobs/JobStatus.php index af77b5a7b..48a2bbf46 100644 --- a/app/Models/Jobs/JobStatus.php +++ b/app/Models/Jobs/JobStatus.php @@ -20,5 +20,6 @@ class JobStatus extends Model protected $fillable = [ 'job_name', 'complete', + 'system_time', ]; } diff --git a/database/migrations/2019_05_05_064022_create_job_status_table.php b/database/migrations/2019_05_05_064022_create_job_status_table.php index 9b1b47286..db15f3c20 100644 --- a/database/migrations/2019_05_05_064022_create_job_status_table.php +++ b/database/migrations/2019_05_05_064022_create_job_status_table.php @@ -18,6 +18,7 @@ class CreateJobStatusTable extends Migration $table->increments('id'); $table->string('job_name'); $table->boolean('complete'); + $table->datetime('system_time'); $table->timestamps(); }); }