WorkflowSchedulerCommand
extends Command
in package
CLI command to check and dispatch scheduled workflow triggers.
Designed to be called frequently (e.g., every minute via system cron). On each invocation it finds workflow definitions with trigger_type='scheduled', evaluates their cron expressions against last_run_at, and dispatches due workflows via TriggerDispatcher. Idempotent — each run is leased while dispatching, and last_run_at advances only after successful dispatch.
Table of Contents
Properties
- $lastResult : array{dispatched: int, skipped: int, errors: int}
- $triggerDispatcher : TriggerDispatcher|null
- Injected dispatcher. Tests may set this manually when constructing the command directly.
Methods
- __construct() : mixed
- defaultName() : string
- execute() : int
- Execute the scheduler command.
- lastResult() : array{dispatched: int, skipped: int, errors: int}
- Return the most recent execution summary.
- setTriggerDispatcher() : void
- Set a custom TriggerDispatcher (for testing).
- buildOptionParser() : ConsoleOptionParser
- isDue() : bool
- Determine if a scheduled workflow is due to run.
- getTriggerDispatcher() : TriggerDispatcher
- Resolve the workflow trigger dispatcher.
- processScheduledWorkflow() : string
- Process a single scheduled workflow definition.
Properties
$lastResult
private
array{dispatched: int, skipped: int, errors: int}
$lastResult
= ['dispatched' => 0, 'skipped' => 0, 'errors' => 0]
$triggerDispatcher
Injected dispatcher. Tests may set this manually when constructing the command directly.
private
TriggerDispatcher|null
$triggerDispatcher
= null
Methods
__construct()
public
__construct([CommandFactoryInterface|null $factory = null ][, TriggerDispatcher|null $triggerDispatcher = null ]) : mixed
Parameters
- $factory : CommandFactoryInterface|null = null
-
Command factory
- $triggerDispatcher : TriggerDispatcher|null = null
-
Workflow trigger dispatcher
defaultName()
public
static defaultName() : string
Tags
Return values
stringexecute()
Execute the scheduler command.
public
execute(Arguments $args, ConsoleIo $io) : int
Parameters
- $args : Arguments
-
Console arguments
- $io : ConsoleIo
-
Console IO
Return values
int —Exit code
lastResult()
Return the most recent execution summary.
public
lastResult() : array{dispatched: int, skipped: int, errors: int}
Return values
array{dispatched: int, skipped: int, errors: int}setTriggerDispatcher()
Set a custom TriggerDispatcher (for testing).
public
setTriggerDispatcher(TriggerDispatcher $dispatcher) : void
Parameters
- $dispatcher : TriggerDispatcher
-
Dispatcher instance
buildOptionParser()
protected
buildOptionParser(ConsoleOptionParser $parser) : ConsoleOptionParser
Parameters
- $parser : ConsoleOptionParser
Tags
Return values
ConsoleOptionParserisDue()
Determine if a scheduled workflow is due to run.
protected
isDue(CronExpression $cron, DateTime|null $lastRunAt, DateTime $now) : bool
Compares the cron expression against the last run time. If the cron expression's previous due date is after the last run time, the workflow is due.
Parameters
- $cron : CronExpression
-
Parsed cron expression
- $lastRunAt : DateTime|null
-
When the workflow last ran
- $now : DateTime
-
Current time
Return values
bool —True if the workflow should run
getTriggerDispatcher()
Resolve the workflow trigger dispatcher.
private
getTriggerDispatcher() : TriggerDispatcher
Return values
TriggerDispatcherprocessScheduledWorkflow()
Process a single scheduled workflow definition.
private
processScheduledWorkflow(WorkflowDefinition $definition, WorkflowSchedulesTable $schedulesTable, bool $dryRun, bool $force, ConsoleIo $io) : string
Parameters
- $definition : WorkflowDefinition
-
Workflow definition
- $schedulesTable : WorkflowSchedulesTable
-
Schedules table
- $dryRun : bool
-
Whether this is a dry run
- $force : bool
-
Force execution regardless of schedule
- $io : ConsoleIo
-
Console IO
Return values
string —'dispatched', 'skipped', or 'error'