|
| 1 | +# CakeDC Queue Monitor Plugin for CakePHP |
| 2 | + |
| 3 | +## Versions and branches |
| 4 | +| CakePHP | CakeDC Queue Monitor Plugin | Tag | Notes | |
| 5 | +|:-------:|:--------------------------------------------------------------------------:|:------------:|:-------| |
| 6 | +| ^5.0 | [2.0.0](https://github.com/CakeDC/cakephp-queue-monitor/tree/2.next-cake5) | 2.next-cake5 | stable | |
| 7 | +| ^4.4 | [1.0.0](https://github.com/CakeDC/cakephp-queue-monitor/tree/1.next-cake4) | 1.next-cake4 | stable | |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +The CakeDC Queue Monitor Plugin adds the ability to monitor jobs in queues that are handled by the |
| 12 | +[CakePHP Queue Plugin](https://github.com/cakephp/queue). This plugin checks the duration of work of |
| 13 | +individual Jobs and sends a notification when this time is exceeded by a configurable value. |
| 14 | + |
| 15 | +## Requirements |
| 16 | +* CakePHP 5.0 |
| 17 | +* PHP 8.1+ |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +You can install this plugin into your CakePHP application using [composer](https://getcomposer.org). |
| 22 | + |
| 23 | +The recommended way to install composer package is: |
| 24 | +``` |
| 25 | +composer require cakedc/queue-monitor |
| 26 | +``` |
| 27 | + |
| 28 | +## Configuration |
| 29 | + |
| 30 | +Add QueueMonitorPlugin to your `Application::bootstrap`: |
| 31 | +```php |
| 32 | +use Cake\Http\BaseApplication; |
| 33 | +use CakeDC\QueueMonitor\QueueMonitorPlugin; |
| 34 | + |
| 35 | +class Application extends BaseApplication |
| 36 | +{ |
| 37 | + // ... |
| 38 | + |
| 39 | + public function bootstrap(): void |
| 40 | + { |
| 41 | + parent::bootstrap(); |
| 42 | + |
| 43 | + $this->addPlugin(QueueMonitorPlugin::class); |
| 44 | + } |
| 45 | + |
| 46 | + // ... |
| 47 | +} |
| 48 | + |
| 49 | +``` |
| 50 | + |
| 51 | +Set up the QueueMonitor configuration in your `config/app_local.php`: |
| 52 | +```php |
| 53 | +// ... |
| 54 | + 'QueueMonitor' => [ |
| 55 | + // mailer config, the default is `default` mailer, you can ommit |
| 56 | + // this setting if you use default value |
| 57 | + 'mailerConfig' => 'myCustomMailer', |
| 58 | + |
| 59 | + // the default is 30 minutes, you can ommit this setting if you |
| 60 | + // use the default value |
| 61 | + 'longJobInMinutes' => 45, |
| 62 | + |
| 63 | + // the default is 30 days, you can ommit this setting if you |
| 64 | + // its advised to set this value correctly after queue usage analysis to avoid |
| 65 | + // high space usage in db |
| 66 | + 'purgeLogsOlderThanDays' => 10, |
| 67 | + |
| 68 | + // comma separated list of recipients of notification about long running queue jobs |
| 69 | + |
| 70 | + ], |
| 71 | +// ... |
| 72 | +``` |
| 73 | + |
| 74 | +Run the required migrations |
| 75 | +```shell |
| 76 | +bin/cake migrations migrate -p CakeDC/QueueMonitor |
| 77 | +``` |
| 78 | + |
| 79 | +For each queue configuration add `listener` setting |
| 80 | +```php |
| 81 | +// ... |
| 82 | + 'Queue' => [ |
| 83 | + 'default' => [ |
| 84 | + // ... |
| 85 | + 'listener' => \CakeDC\QueueMonitor\Listener\QueueMonitorListener::class, |
| 86 | + // ... |
| 87 | + ] |
| 88 | + ], |
| 89 | +// ... |
| 90 | +``` |
| 91 | + |
| 92 | +## Notification command |
| 93 | + |
| 94 | +To set up notifications when there are long running or possible stuck jobs please use command |
| 95 | +```shell |
| 96 | +bin/cake queue_monitor notify |
| 97 | +``` |
| 98 | + |
| 99 | +This command will send notification emails to recipients specified in `QueueMonitor.notificationRecipients`. Best is |
| 100 | +to use it as a cronjob |
| 101 | + |
| 102 | +## Purge command |
| 103 | + |
| 104 | +The logs table may grow overtime, to keep it slim you can use the purge command: |
| 105 | +```shell |
| 106 | +bin/cake queue_monitor purge |
| 107 | +``` |
| 108 | + |
| 109 | +This command will purge logs older than value specified in `QueueMonitor.purgeLogsOlderThanDays`, the value is in |
| 110 | +days, the default is 30 days. Best is to use it as a cronjob |
| 111 | + |
| 112 | +## Important |
| 113 | + |
| 114 | +Make sure your Job classes have a property value of maxAttempts because if it's missing, the log table can quickly |
| 115 | +grow to gigantic size in the event of an uncaught exception in Job, Job is re-queued indefinitely in such a case. |
0 commit comments