如果排隊作業失敗,此包會發送通知。開箱即用,它可以透過郵件和/或 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)。請參閱許可證文件以獲取更多資訊。