Update
This commit is contained in:
27
app/Observers/CrawlShotJobObserver.php
Normal file
27
app/Observers/CrawlShotJobObserver.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\CrawlShotJob;
|
||||
use App\Services\WebhookService;
|
||||
|
||||
class CrawlShotJobObserver
|
||||
{
|
||||
public function updated(CrawlShotJob $crawlShotJob): void
|
||||
{
|
||||
// Only fire webhook if status has changed and webhook_url is set
|
||||
if ($crawlShotJob->isDirty('status') && $crawlShotJob->webhook_url) {
|
||||
$eventsFilter = $crawlShotJob->webhook_events_filter ?? ['queued', 'processing', 'completed', 'failed'];
|
||||
|
||||
// Don't fire webhook if filter is empty array
|
||||
if (empty($eventsFilter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only fire webhook if current status is in the filter
|
||||
if (in_array($crawlShotJob->status, $eventsFilter)) {
|
||||
WebhookService::send($crawlShotJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user