feat: Phase 4 - Mailwizz integration with subscriber sync and retry
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\DispatchUnsyncedMailwizzSyncJobsService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class QueueUnsyncedMailwizzSubscribersCommand extends Command
|
||||
{
|
||||
protected $signature = 'mailwizz:queue-unsynced
|
||||
{--page= : Limit to a preregistration page ID}
|
||||
{--dry-run : Only show how many subscribers would be processed}';
|
||||
|
||||
protected $description = 'Queue Mailwizz sync jobs for subscribers not yet synced (skips duplicates already queued via unique job lock)';
|
||||
|
||||
public function handle(DispatchUnsyncedMailwizzSyncJobsService $dispatcher): int
|
||||
{
|
||||
$pageOption = $this->option('page');
|
||||
$pageId = null;
|
||||
if ($pageOption !== null && $pageOption !== '') {
|
||||
if (! is_numeric($pageOption)) {
|
||||
$this->error(__('The --page option must be a numeric ID.'));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
$pageId = (int) $pageOption;
|
||||
}
|
||||
|
||||
$eligible = $dispatcher->eligibleSubscribersQuery()
|
||||
->when($pageId !== null, fn ($q) => $q->where('preregistration_page_id', $pageId))
|
||||
->count();
|
||||
|
||||
if ($this->option('dry-run')) {
|
||||
$this->info(__(':count subscriber(s) would be processed.', ['count' => $eligible]));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$processed = $dispatcher->dispatch($pageId);
|
||||
$this->info(__('Queued sync for :count subscriber(s). Duplicate jobs for the same subscriber are skipped while one is already pending.', ['count' => $processed]));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user