Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

priority queue #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Jobs/ProcessANPCAllData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ProcessICNFPDFData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/UpdateICNFData.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function handle()
->get();

foreach ($incidents as $incident) {
dispatch(new ProcessICNFFireData($incident));
dispatch((new ProcessICNFFireData($incident))->onQueue('low'));
}
}
}
13 changes: 7 additions & 6 deletions app/Observers/IncidentObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
59 changes: 59 additions & 0 deletions config/queue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Default Queue Connection Name
|--------------------------------------------------------------------------
|
| Laravel's queue API supports an assortment of back-ends via a single
| API, giving you convenient access to each back-end using the same
| syntax for every one. Here you may define a default connection.
|
*/

'default' => env('QUEUE_CONNECTION', 'sync'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the default set as sync because of the scheduled jobs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's the default, didn't change it. Should it be redis_low or redis_high?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just redis.


/*
|--------------------------------------------------------------------------
| 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,
],
Comment on lines +40 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although we're defining these new connections, no job is using them. The jobs have different queues associated, but since we're not declaring different connections, they're all being sent to the default connection (redis).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed it, but the queue name is not the connection name, which was what we are defining here. We can have one connection that handles multiple queues. So, to put it simply: we should keep one Redis connection.

],


];
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,default,low --sleep=3 --tries=3 --max-time=3600

volumes:
mongodb_data:
Expand Down