Files
crawlshot/app/Observers/CrawlShotJobObserver.php
2025-08-11 02:35:35 +08:00

28 lines
844 B
PHP

<?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);
}
}
}
}