cakedc/queue-monitor

CakeDC Queue Monitor plugin for CakePHP

Installs: 4 359

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 10

Forks: 0

Open Issues: 0

Type:cakephp-plugin

2.1.0 2024-12-10 10:01 UTC

README

Versions and branches

Overview

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.

Requirements

  • CakePHP 5.0
  • PHP 8.1+

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer package is:

composer require cakedc/queue-monitor

Configuration

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' => 'recipient1@yourdomain.com,recipient2@yourdomain.com,recipient3@yourdomain.com',
    ],
// ...

For each queue configuration add listener setting

// ...
    'Queue' => [
        'default' => [
            // ...
            'listener' => \CakeDC\QueueMonitor\Listener\QueueMonitorListener::class,
            // ...
        ]
    ],
// ...

Notification command

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.

Test Enqueue command

To quickly test if all queues are running correctly please run this command (replace your-email@domain.com with working email address:

bin/cake queue-monitor test-enqueue your-email@domain.com

This command will send the command through all configured queues.

Purge queues command

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

Purge Logs command

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

Important

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.