From e949b1d717654777ee008088fea97c48604fb532 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Wed, 19 May 2021 00:46:22 +0900 Subject: [PATCH] added queue to horizon schedule in the kernel for console commands and scheduler --- .../ExecuteFetchAllianceAssetsCommand.php | 2 +- app/Console/Kernel.php | 35 ++++++++++++------- .../Commands/Assets/ProcessAllianceAssets.php | 6 +++- .../Structures/ProcessAllianceStructures.php | 19 ++++------ config/horizon.php | 4 +-- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/Console/Commands/Structures/ExecuteFetchAllianceAssetsCommand.php b/app/Console/Commands/Structures/ExecuteFetchAllianceAssetsCommand.php index dad27d264..9102485b4 100644 --- a/app/Console/Commands/Structures/ExecuteFetchAllianceAssetsCommand.php +++ b/app/Console/Commands/Structures/ExecuteFetchAllianceAssetsCommand.php @@ -39,7 +39,7 @@ class ExecuteFetchAllianceAssetsCommand extends Command */ public function handle() { - FAA::dispatch()->onQueue('structures'); + FAA::dispatch()->onQueue('assets'); return 0; } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 2eaf3f632..0c4c1bd96 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -60,70 +60,71 @@ class Kernel extends ConsoleKernel * Purge Data Schedule */ $schedule->job(new PurgeUsersJob) + ->onQueue('default') ->weekly(); /** * Finances Update Schedule */ $schedule->job(new UpdateAllianceWalletJournalJob) - ->timezone('UTC') ->hourlyAt('45') + ->onQueue('finances') ->withoutOverlapping(); /** * Item Update Schedule */ $schedule->job(new UpdateItemPricesJob) - ->timezone('UTC') ->hourlyAT('30') + ->onQueue('default'); ->withoutOverlapping(); /** * Mining Tax Schedule */ $schedule->job(new FetchMiningTaxesObservers) - ->timezone('UTC') ->dailyAt('22:00') + ->onQueue('miningtaxes') ->withoutOverlapping(); $schedule->job(new PreFetchMiningTaxesLedgers) - ->timezone('UTC') ->dailyAt('20:00') + ->onQueue('miningtaxes') ->withoutOverlapping(); $schedule->job(new SendMiningTaxesInvoices) - ->timezone('UTC') ->weeklyOn(1, '06:00') + ->onQueue('miningtaxes') ->withoutOverlapping(); $schedule->job(new ProcessMiningTaxesPayments) - ->timezone('UTC') ->hourlyAt('15') + ->onQueue('miningtaxes') ->withoutOverlapping(); $schedule->job(new UpdateMiningTaxesLateInvoices1st) - ->timezone('UTC') ->monthlyOn(1, '16:00') + ->onQueue('miningtaxes') ->withoutOverlapping(); $schedule->job(new UpdateMiningTaxesLateInvoices15th) - ->timezone('UTC') ->monthlyOn(15, '16:00') + ->onQueue('miningtaxes') ->withoutOverlapping(); /** * Alliance Structure and Assets Schedule */ $schedule->job(new FetchAllianceStructures) - ->timezone('UTC') ->dailyAt('21:00') + ->onQueue('structures') ->withoutOverlapping(); $schedule->job(new FetchAllianceAssets) - ->timezone('UTC') ->hourlyAt('15') + ->onQueue('structures') ->withoutOverlapping(); $schedule->job(new PurgeAllianceStructures) - ->timezone('UTC') ->monthlyOn(2, '14:00') + ->onQueue('structures') ->withoutOverlapping(); $schedule->job(new PurgeAllianceAssets) - ->timezone('UTC') ->monthlyOn(2, '15:00') + ->onQueue('structures') ->withoutOverlapping(); } @@ -139,4 +140,14 @@ class Kernel extends ConsoleKernel require base_path('routes/console.php'); } + + /** + * Get the timezone that should be used by default for scheduled events. + * + * @return \DateTimeZone|string|null + */ + protected function scheduleTimezone() + { + return 'UTC'; + } } diff --git a/app/Jobs/Commands/Assets/ProcessAllianceAssets.php b/app/Jobs/Commands/Assets/ProcessAllianceAssets.php index 957bcc4d3..c1e7d5a69 100644 --- a/app/Jobs/Commands/Assets/ProcessAllianceAssets.php +++ b/app/Jobs/Commands/Assets/ProcessAllianceAssets.php @@ -57,7 +57,11 @@ class ProcessAllianceAssets implements ShouldQueue * If the asset is not in the database, then let's save it to the database, * otherwise, we just update the old asset */ - if(Asset::where(['item_id' => $this->asset->item_id])->count() == 0) { + $count = Asset::where([ + 'item_id' => $this->asset->item_id, + ])->count(); + + if($count == 0) { $as = new Asset; if(isset($this->asset->is_blueprint_copy)) { $as->is_blueprint_copy = $this->asset->is_blueprint_copy; diff --git a/app/Jobs/Commands/Structures/ProcessAllianceStructures.php b/app/Jobs/Commands/Structures/ProcessAllianceStructures.php index 78eaf9378..450577465 100644 --- a/app/Jobs/Commands/Structures/ProcessAllianceStructures.php +++ b/app/Jobs/Commands/Structures/ProcessAllianceStructures.php @@ -13,9 +13,6 @@ use Illuminate\Queue\SerializesModels; use App\Library\Helpers\LookupHelper; use App\Library\Esi\Esi; -//Jobs -use App\Jobs\Commands\Structures\ProcessAllianceStructureServices; - //Models use App\Models\Structure\Structure; use App\Models\Structure\Service; @@ -98,6 +95,12 @@ class ProcessAllianceStructures implements ShouldQueue $s->corporation_id = $structure->corporation_id; if(isset($structure->services)) { $s->services = true; + foreach($structure->services as $service) { + $serv = new Service; + $serv->structure_id = $structure->structure_id; + $serv->name = $service->name; + $serv->state = $service->state; + } } else { $s->services = false; } @@ -123,16 +126,6 @@ class ProcessAllianceStructures implements ShouldQueue $s->unanchors_at = $esiHelper->DecodeDate($s->unanchors_at); } $s->save(); - - //If there are services on the structure, then save the service and the structure id in the database table. - if($s->services == true) { - foreach($structure->services as $service) { - $serv = new Service; - $serv->structure_id = $structure->structure_id; - $serv->name = $service->name; - $serv->state = $service->state; - } - } } private function UpdateStructure($structure) { diff --git a/config/horizon.php b/config/horizon.php index d0c9e48a4..303337a4f 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -154,7 +154,7 @@ return [ 'balance' => 'auto', 'processes' => 12, 'minProcesses' => 1, - 'maxProcesses' => 12, + 'maxProcesses' => 10, 'balanceMaxShift' => 2, 'balanceCooldown' => 5, 'tries' => 3, @@ -175,7 +175,7 @@ return [ 'balance' => 'auto', 'processes' => 12, 'minProcesses' => 1, - 'maxProcesses' => 12, + 'maxProcesses' => 10, 'balanceMaxShift' => 2, 'balanceCooldown' => 5, 'tries' => 3,