แพ็คเกจนี้จะส่งการแจ้งเตือนหากงานที่อยู่ในคิวล้มเหลว เมื่อแกะกล่อง ก็สามารถส่งการแจ้งเตือนทางไปรษณีย์และ/หรือ Slack ได้ มันใช้ประโยชน์จากระบบการแจ้งเตือนดั้งเดิมของ Laravel
เราลงทุนทรัพยากรจำนวนมากเพื่อสร้างแพ็คเกจโอเพ่นซอร์สที่ดีที่สุดในระดับเดียวกัน คุณสามารถสนับสนุนเราได้โดยการซื้อหนึ่งในผลิตภัณฑ์ที่ต้องชำระเงินของเรา
เราขอขอบคุณอย่างยิ่งที่คุณส่งโปสการ์ดจากบ้านเกิดของคุณถึงเรา โดยระบุว่าคุณใช้แพ็คเกจใดของเรา คุณจะพบที่อยู่ของเราในหน้าติดต่อของเรา เราเผยแพร่โปสการ์ดที่ได้รับทั้งหมดบนวอลล์โปสการ์ดเสมือนของเรา
สำหรับ Laravel เวอร์ชัน 5.8 และ 6.x ให้ใช้ v3.x ของแพ็คเกจนี้
คุณสามารถติดตั้งแพ็คเกจผ่านทางผู้แต่ง:
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,
...
คลาสการแจ้งเตือนเริ่มต้นที่จัดทำโดยแพ็คเกจนี้ใช้ channels
เนล mail
และคีย์ slack
จากไฟล์ config
เพื่อกำหนดวิธีการส่งการแจ้งเตือน
หากคุณต้องการปรับแต่งการแจ้งเตือน คุณสามารถระบุคลาสการแจ้งเตือนของคุณเองได้ในไฟล์กำหนดค่า
// 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.
มันจะดีกว่าถ้าสร้างคลาสแยกต่างหากและใช้ callable เป็นตัวโทรกลับ
<?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] แทนการใช้ตัวติดตามปัญหา
ขอขอบคุณ Egor Talantsev เป็นอย่างยิ่งสำหรับความช่วยเหลือในการสร้างแพ็คเกจ v2
ใบอนุญาตเอ็มไอที (MIT) โปรดดูไฟล์ใบอนุญาตสำหรับข้อมูลเพิ่มเติม