From 06eb3b25f06c529a6050659e2f7e0eeba36152dd Mon Sep 17 00:00:00 2001 From: Tomahock Date: Tue, 13 Jul 2021 10:33:02 +0100 Subject: [PATCH 1/2] priority queue --- app/Jobs/ProcessANPCAllData.php | 4 ++-- app/Jobs/ProcessICNFPDFData.php | 2 +- app/Jobs/UpdateICNFData.php | 2 +- app/Observers/IncidentObserver.php | 13 +++++++------ docker-compose.yml | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/Jobs/ProcessANPCAllData.php b/app/Jobs/ProcessANPCAllData.php index 3e0f93c..c9001db 100644 --- a/app/Jobs/ProcessANPCAllData.php +++ b/app/Jobs/ProcessANPCAllData.php @@ -50,8 +50,8 @@ public function handle() $this->handleIncidents($incidents); - dispatch(new CheckIsActive($incidents)); - dispatch(new CheckImportantFireIncident()); + dispatch((new CheckIsActive($incidents))->onQueue('high')); + dispatch((new CheckImportantFireIncident())->onQueue('low')); } private function handleIncidents($data) diff --git a/app/Jobs/ProcessICNFPDFData.php b/app/Jobs/ProcessICNFPDFData.php index 41b8cf0..1060e3c 100644 --- a/app/Jobs/ProcessICNFPDFData.php +++ b/app/Jobs/ProcessICNFPDFData.php @@ -87,7 +87,7 @@ public function handle() $fileId = $match[1]; $url = env('ICNF_PDF_URL').$fileId; - dispatch(new ProcessICNFPDF($this->incident[0], $url)); + dispatch((new ProcessICNFPDF($this->incident[0], $url))->onQueue('low')); } } } diff --git a/app/Jobs/UpdateICNFData.php b/app/Jobs/UpdateICNFData.php index 934caf7..e4c5940 100644 --- a/app/Jobs/UpdateICNFData.php +++ b/app/Jobs/UpdateICNFData.php @@ -82,7 +82,7 @@ public function handle() ->get(); foreach ($incidents as $incident) { - dispatch(new ProcessICNFFireData($incident)); + dispatch((new ProcessICNFFireData($incident))->onQueue('low')); } } } diff --git a/app/Observers/IncidentObserver.php b/app/Observers/IncidentObserver.php index 527d45c..7675047 100644 --- a/app/Observers/IncidentObserver.php +++ b/app/Observers/IncidentObserver.php @@ -16,18 +16,19 @@ protected static function boot() static::created(function ($incident) { //Log::info("Incident Created Event Fire observer: ".$incident); - dispatch(new SaveIncidentHistory($incident)); - dispatch(new SaveIncidentStatusHistory($incident)); + dispatch((new SaveIncidentHistory($incident))->onQueue('low')); + dispatch((new SaveIncidentStatusHistory($incident))->onQueue('low')); + dispatch((new SaveIncidentStatusHistory($incident))->onQueue('low')); if ($incident->isFire) { - dispatch(new HandleNewIncidentSocialMedia($incident)); - dispatch(new ProcessICNFFireData($incident)); + dispatch((new HandleNewIncidentSocialMedia($incident))->onQueue('high')); + dispatch((new ProcessICNFFireData($incident))->onQueue('low')); } }); static::updated(function ($incident) { //Log::info("Incident updated Event Fire observer: ".$incident); - dispatch(new SaveIncidentStatusHistory($incident)); - dispatch(new SaveIncidentHistory($incident)); + dispatch((new SaveIncidentStatusHistory($incident))->onQueue('low')); + dispatch((new SaveIncidentHistory($incident))->onQueue('low')); }); static::deleted(function ($incident) { diff --git a/docker-compose.yml b/docker-compose.yml index 4dab9bd..9e132da 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -87,7 +87,7 @@ services: - fogos.mongodb networks: - fogos - command: php artisan queue:work --sleep=3 --tries=3 --max-time=3600 + command: php artisan queue:work --queue=high,low --sleep=3 --tries=3 --max-time=3600 volumes: mongodb_data: From ca982e9d8571d2d8b407c42ff006eeb5017f23b2 Mon Sep 17 00:00:00 2001 From: Tomahock Date: Tue, 13 Jul 2021 12:05:19 +0100 Subject: [PATCH 2/2] add high and low queue to config --- config/queue.php | 59 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 config/queue.php diff --git a/config/queue.php b/config/queue.php new file mode 100644 index 0000000..b378124 --- /dev/null +++ b/config/queue.php @@ -0,0 +1,59 @@ + env('QUEUE_CONNECTION', 'sync'), + + /* + |-------------------------------------------------------------------------- + | Queue Connections + |-------------------------------------------------------------------------- + | + | Here you may configure the connection information for each server that + | is used by your application. A default configuration has been added + | for each back-end shipped with Laravel. You are free to add more. + | + | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" + | + */ + + 'connections' => [ + 'redis' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => env('REDIS_QUEUE', 'default'), + 'retry_after' => 90, + 'block_for' => null, + 'after_commit' => false, + ], + 'redis_high' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'high', + 'retry_after' => 90, + 'block_for' => null, + 'after_commit' => false, + ], + 'redis_low' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'low', + 'retry_after' => 90, + 'block_for' => null, + 'after_commit' => false, + ], + ], + + +]; diff --git a/docker-compose.yml b/docker-compose.yml index 9e132da..df2cc73 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -87,7 +87,7 @@ services: - fogos.mongodb networks: - fogos - command: php artisan queue:work --queue=high,low --sleep=3 --tries=3 --max-time=3600 + command: php artisan queue:work --queue=high,default,low --sleep=3 --tries=3 --max-time=3600 volumes: mongodb_data: