cakedc / queue-monitor
CakeDC Queue Monitor 插件用于 CakePHP
2.0.1
2024-05-14 14:54 UTC
Requires
- php: >=8.1
- ext-json: *
- cakephp/cakephp: ^5.0.1
- cakephp/queue: ^2.0
Requires (Dev)
- cakephp/cakephp-codesniffer: ^5.1
- cakephp/migrations: ^4.0.0
- phpunit/phpunit: ^10.1.0
This package is auto-updated.
Last update: 2024-09-08 08:19:12 UTC
README
版本和分支
概述
CakeDC Queue Monitor 插件增加了监控由 CakePHP Queue 插件 处理的队列中作业的能力。此插件检查单个作业的工作持续时间,当超出可配置值时发送通知。
需求
- CakePHP 5.0
- PHP 8.1+
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方法是
composer require cakedc/queue-monitor
配置
将 QueueMonitorPlugin 添加到您的 Application::bootstrap
use Cake\Http\BaseApplication; use CakeDC\QueueMonitor\QueueMonitorPlugin; class Application extends BaseApplication { // ... public function bootstrap(): void { parent::bootstrap(); $this->addPlugin(QueueMonitorPlugin::class); } // ... }
在您的 config/app_local.php
中设置 QueueMonitor 配置
// ... 'QueueMonitor' => [ // mailer config, the default is `default` mailer, you can ommit // this setting if you use default value 'mailerConfig' => 'myCustomMailer', // the default is 30 minutes, you can ommit this setting if you // use the default value 'longJobInMinutes' => 45, // the default is 30 days, you can ommit this setting if you // its advised to set this value correctly after queue usage analysis to avoid // high space usage in db 'purgeLogsOlderThanDays' => 10, // comma separated list of recipients of notification about long running queue jobs 'notificationRecipients' => 'recipient1@yourdomain.com,recipient2@yourdomain.com,recipient3@yourdomain.com', ], // ...
运行所需的迁移
bin/cake migrations migrate -p CakeDC/QueueMonitor
为每个队列配置添加 listener
设置
// ... 'Queue' => [ 'default' => [ // ... 'listener' => \CakeDC\QueueMonitor\Listener\QueueMonitorListener::class, // ... ] ], // ...
通知命令
要设置长时间运行或可能卡住的作业的通知,请使用以下命令
bin/cake queue_monitor notify
此命令将向在 QueueMonitor.notificationRecipients
中指定的收件人发送通知电子邮件。最好将其用作 cronjob
清除命令
日志表可能会随时间增长,为了保持其精简,您可以使用清除命令
bin/cake queue_monitor purge
此命令将清除在 QueueMonitor.purgeLogsOlderThanDays
中指定的值之前的老旧日志,该值以天为单位,默认为 30 天。最好将其用作 cronjob
重要
确保您的作业类有 maxAttempts 属性值,因为如果它缺失,在作业中未捕获到异常时,日志表可以迅速增长到巨大的大小,在这种情况下,作业将被无限期地重新排队。