Files
ladill-frontdesk/app/Jobs/DispatchCampaignJob.php
T
isaaccladandCursor 9e2d79936c
Deploy Ladill Frontdesk / deploy (push) Failing after 35s
Test / test (push) Failing after 2m45s
Initial Ladill Frontdesk release with deploy pipeline.
Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 20:37:15 +00:00

44 lines
1.1 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\Campaign;
use App\Models\CampaignRecipient;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
class DispatchCampaignJob implements ShouldQueue
{
use Queueable;
public function __construct(public int $campaignId)
{
}
public function handle(): void
{
$campaign = Campaign::query()->find($this->campaignId);
if (! $campaign || ! in_array($campaign->status, [Campaign::STATUS_QUEUED, Campaign::STATUS_SENDING], true)) {
return;
}
if ($campaign->recipient_count === 0) {
$campaign->forceFill([
'status' => Campaign::STATUS_FAILED,
'completed_at' => now(),
])->save();
return;
}
$campaign->forceFill(['status' => Campaign::STATUS_SENDING])->save();
$campaign->recipients()
->where('status', CampaignRecipient::STATUS_PENDING)
->orderBy('id')
->pluck('id')
->each(fn (int $recipientId) => SendCampaignMessageJob::dispatch($recipientId));
}
}