Deploy Ladill Frontdesk / deploy (push) Successful in 45s
NotificationDispatcher sends via customer relay and skips Frontdesk wallet debit when tenant keys are configured. Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Campaign;
|
|
use App\Models\CampaignRecipient;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
|
|
/**
|
|
* Campaign batch dispatch — orphaned until Campaign model exists.
|
|
*/
|
|
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));
|
|
}
|
|
}
|