talvbansal/laravel-throttled-failed-jobs

当队列中的作业失败时收到通知,但不要太频繁

1.1.1 2020-03-12 15:15 UTC

This package is auto-updated.

Last update: 2024-08-30 01:09:46 UTC


README

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

此包会在队列作业失败时发送通知。然而,有时作业在失败时会导致过多的通知,因此对这些作业进行节流是有用的。它默认可以通过邮件、Slack 和 Microsoft Teams 发送通知。它利用 Laravel 的原生通知系统。

此包基于 Spatie 的 Laravel failed job monitor,由 Spatie 提供。

安装

您可以通过 composer 安装此包。

composer require talvbansal/laravel-throttled-failed-jobs

服务提供程序将自动注册。

接下来,您必须发布配置文件

php artisan vendor:publish --provider="TalvBansal\ThrottledFailedJobMonitor\FailedThrottledJobsServiceProvider"

这是默认配置文件的内容。在这里,您可以指定应发送通知的可通知对象。默认可通知对象将使用此配置文件中指定的变量。

return [

    /*
     * The notification that will be sent when a job fails.
     */
    'notification' => \TalvBansal\ThrottledFailedJobMonitor\Notification::class,

    /*
     * The notifiable to which the notification will be sent. The default
     * notifiable will use the mail and slack configuration specified
     * in this config file.
     */
    'notifiable' => \TalvBansal\ThrottledFailedJobMonitor\Notifiable::class,

    /*
     * By default notifications are sent for all failures. You can pass a callable to filter
     * out certain notifications. The given callable will receive the notification. If the callable
     * return false, the notification will not be sent.
     */
    'notificationFilter' => null,

    /*
     * The channels to which the notification will be sent.
     */
    'channels' => ['mail', 'slack', 'msteams'],

    'mail' => [
        'to' => 'email@example.com',
    ],

    'slack' => [
        'webhook_url' => env('FAILED_JOB_SLACK_WEBHOOK_URL'),
    ],

    'ms-teams' => [
        'webhook_url' => env('MS_TEAMS_WEBHOOK_URL'),
    ],

    /*
     * The length of the throttle window in minutes. Eg: 10 would mean
     * only one notification of certain type would be actually sent
     * within a 10 minute window...
     */
    'throttle_decay' => 10,
];

配置

自定义通知

此包提供的默认通知类支持邮件、Slack 和 MS Teams

如果您想自定义通知,可以在配置文件中指定您自己的通知类。

// config/throttled-failed-jobs.php
return [
    ...
    'notification' => \App\Notifications\CustomNotificationForFailedJobMonitor::class,
    ...

自定义可通知对象

此包提供的默认可通知对象使用 channelsmailslack 键从 config 文件中确定如何发送通知。

如果您想自定义可通知对象,可以在配置文件中指定您自己的可通知对象类。

// config/throttled-failed-jobs.php
return [
    'notifiable' => \App\CustomNotifiableForFailedJobMonitor::class,
    ...

自定义节流窗口

默认配置将每个通知类型设置为 10 分钟的窗口。您可以在配置文件中轻松更改窗口的长度,以便在 x 分钟内只收到一种类型的通知。

// config/throttled-failed-jobs.php
return [
        'throttle_decay' => 10,
    ...

使用方法

如果您正确配置了此包,则已完成。当队列作业失败时,您将收到通知。

变更日志

请参阅CHANGELOG 以获取最近更改的更多信息。

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过 :author_email 发送电子邮件,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅CONTRIBUTING

鸣谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件

有关提交渠道提案的说明,请参阅 此存储库