このパッケージは、キューに入れられたジョブが失敗した場合に通知を送信します。すぐに使用できるように、メールや 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 ' ],
...
パッケージを正しく構成すれば、作業は完了です。キューに入れられたジョブが失敗すると、通知が届きます。
最近の変更点の詳細については、CHANGELOG を参照してください。
composer test
詳細については、「貢献」を参照してください。
セキュリティに関するバグを見つけた場合は、問題トラッカーを使用する代わりに [email protected] にメールを送信してください。
パッケージのv2
作成に協力してくれた Egor Tarantsev に多大な感謝を申し上げます。
MIT ライセンス (MIT)。詳細については、ライセンス ファイルを参照してください。