* Manual automations * Scheduled automations * Incoming webhook triggers * Domain-event trigger foundation * Ordered automation steps * Queued execution * Run status and execution history * Per-step execution logs * Continue-or-stop-on-failure control * Email actions * Outgoing webhook actions * Application log actions * Delay actions * Secure incoming webhook secrets * Automation trigger and action registries * Extensible action and trigger contracts * Scheduled automation Artisan command * Administration navigation * Automation permissions * Module registration and boot test
16 lines
1019 B
PHP
16 lines
1019 B
PHP
<?php
|
|
namespace Modules\Automation\Console;
|
|
use Illuminate\Console\Command;
|
|
use Modules\Automation\Models\Automation;
|
|
use Modules\Automation\Services\AutomationRunner;
|
|
final class DispatchScheduledAutomations extends Command
|
|
{
|
|
protected $signature='automation:dispatch-scheduled';
|
|
protected $description='Dispatch active automations whose next run time is due.';
|
|
public function handle(AutomationRunner $runner): int
|
|
{
|
|
$count=0; Automation::query()->where('status','active')->where('trigger_type','schedule')->whereNotNull('next_run_at')->where('next_run_at','<=',now())->chunkById(100,function($items)use($runner,&$count){foreach($items as $automation){$runner->dispatch($automation,['scheduled_at'=>now()->toIso8601String()],'schedule');$interval=max(1,(int)($automation->trigger_config['interval_minutes']??60));$automation->update(['next_run_at'=>now()->addMinutes($interval)]);$count++;}});
|
|
$this->info("Dispatched {$count} scheduled automation(s)."); return self::SUCCESS;
|
|
}
|
|
}
|