CakePHP | CakeDC Queue Monitor Plugin | Tag | Notes |
---|---|---|---|
^5.0 | 2.1.0 | 2.next-cake5 | stable |
^4.4 | 1.0.0 | 1.next-cake4 | stable |
The CakeDC Queue Monitor Plugin adds the ability to monitor jobs in queues that are handled by the CakePHP Queue Plugin. This plugin checks the duration of work of individual Jobs and sends a notification when this time is exceeded by a configurable value.
- CakePHP 5.0
- PHP 8.1+
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer package is:
composer require cakedc/queue-monitor
Add QueueMonitorPlugin to your application by running command:
bin/cake plugin load CakeDC/QueueMonitor
Run the required migrations
bin/cake migrations migrate -p CakeDC/QueueMonitor
Set up the QueueMonitor configuration in your config/app_local.php
:
// ...
'QueueMonitor' => [
// With this setting you can enable or disable the queue monitoring, the queue
// monitoring is enabled by default
'disable' => false,
// mailer config, the default is `default` mailer, you can ommit
// this setting if you use default value
'mailerConfig' => 'default',
// the default is 30 minutes, you can ommit this setting if you use the default value
'longJobInMinutes' => 30,
// the default is 7 days, you can ommit this setting if you use the default value
// its advised to set this value correctly after queue usage analysis to avoid
// high space usage in db
'purgeLogsOlderThanDays' => 7,
// comma separated list of recipients of notification about long running queue jobs
'notificationRecipients' => '[email protected],[email protected],[email protected]',
],
// ...
For each queue configuration add listener
setting
// ...
'Queue' => [
'default' => [
// ...
'listener' => \CakeDC\QueueMonitor\Listener\QueueMonitorListener::class,
// ...
]
],
// ...
To set up notifications when there are jobs running for a long time or jobs that may be stuck and blocking the queue please use command:
bin/cake queue-monitor notify
This command will send notification emails to recipients specified in QueueMonitor.notificationRecipients
. Best is
to use it as a cronjob.
To quickly test if all queues are running correctly please run this command (replace [email protected]
with working
email address:
bin/cake queue-monitor test-enqueue [email protected]
This command will send the command through all configured queues.
To purge the content of a specified queue you can use the purge queue command:
bin/cake queue-monitor purge-queue your-queue-name
The above command will remove all pending queue jobs from the specified queue.
To purge all queues you can use command:
bin/cake queue-monitor purge-queue --all
The logs table may grow overtime, to keep it slim you can use the purge command:
bin/cake queue-monitor purge-logs
This command will purge logs older than value specified in QueueMonitor.purgeLogsOlderThanDays
, the value is in
days, the default is 30 days. Best is to use it as a cronjob
Make sure your Job classes have a property value of maxAttempts because if it's missing, the log table can quickly grow to gigantic size in the event of an uncaught exception in Job, Job is re-queued indefinitely in such a case.