如果排队作业失败,此包会发送通知。开箱即用,它可以通过邮件和/或 Slack 发送通知。它利用 Laravel 的本机通知系统。
我们投入了大量资源来创建一流的开源包。您可以通过购买我们的一款付费产品来支持我们。
我们非常感谢您从家乡寄给我们一张明信片,并注明您正在使用我们的哪种套餐。您可以在我们的联系页面上找到我们的地址。我们在虚拟明信片墙上发布所有收到的明信片。
对于 Laravel 版本 5.8 和 6.x,请使用此包的 v3.x。
您可以通过 Composer 安装该软件包:
composer require spatie/laravel-failed-job-monitor
如果您打算使用 Slack 通知,您还应该安装 guzzle 客户端:
composer require guzzlehttp/guzzle
服务提供商将自动注册。
接下来,您必须发布配置文件:
php artisan vendor:publish --tag=failed-job-monitor-config
这是默认配置文件的内容。您可以在此处指定通知应发送到的可通知对象。默认通知将使用此配置文件中指定的变量。
return [
/ * *
* The notification that will be sent when a job fails .
* /
' notification ' => Spatie FailedJobMonitor 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 ' => Spatie FailedJobMonitor 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 ' ],
' mail ' => [
' to ' => [ ' [email protected] ' ],
],
' slack ' => [
' webhook_url ' => env ( ' FAILED_JOB_SLACK_WEBHOOK_URL ' ),
],
];
该包提供的默认通知类支持邮件和 Slack。
如果您想自定义通知,您可以在配置文件中指定您自己的通知类。
// config / failed - job - monitor . php
return [
...
' notification ' => App Notifications CustomNotificationForFailedJobMonitor::class,
...
该包提供的默认通知类使用配置config
中的channels
、 mail
和slack
键来确定必须如何发送通知。
如果您想自定义可通知的,您可以在配置文件中指定您自己的可通知的类。
// config / failed - job - monitor . php
return [
' notifiable ' => App CustomNotifiableForFailedJobMonitor::class,
...
要过滤通知,请将闭包传递给notificationFilter
。
// config / failed - job - monitor . php
return [
...
' notificationFilter ' => function ( Spatie FailedJobMonitor Notification $ notification ): bool
{
return true ;
}
. . .
以上仅适用于 Laravel 不支持闭包序列化。因此,当您运行php artisan config:cache
时,您将收到以下错误
LogicException : Your configuration files are not serializable.
因此,最好创建一个单独的类并使用可调用对象作为回调。
<?php
namespace App Notifications ;
use Spatie FailedJobMonitor Notification ;
class FailedJobNotification
{
public static function notificationFilter ( Notification $ notification ): bool
{
return true ;
}
}
并在配置文件中引用它。
// config / failed - job - monitor . php
return [
...
' notificationFilter ' => [ App Notifications FailedJobNotification::class, ' notificationFilter ' ],
...
如果您正确配置了包,那么您就完成了。当排队作业失败时,您将收到通知。
请参阅变更日志以了解最近更改的更多信息。
composer test
详细信息请参阅贡献。
如果您发现有关安全的错误,请发送邮件至 [email protected],而不是使用问题跟踪器。
非常感谢 Egor Talantsev 帮助创建该软件包的v2
。
麻省理工学院许可证 (MIT)。请参阅许可证文件以获取更多信息。