Skip to content
docsv0.1.1

TaskDefinition

A named unit of scheduled work: a human-readable `$name`, the cron expression that gates when it runs, and the `$callback` a runner ({@see CronRunner}, Task 10) invokes when it's due. Hosts and plugins ({@see CronProviderInterface}) construct these; this package never runs the callback itself — {@see self::isDue()} only answers "should this run now?".

TaskDefinition::__construct()

public function __construct(string $name, string $expression, Closure $callback, string $description = ''):

Parameters

Parameters of __construct()
NameTypeDescription
$namestring
$expressionstring
$callbackClosure
$descriptionstring

Throws

\InvalidArgumentException if `$expression` is not a valid 5-field cron expression — see {@see CronExpression::__construct()}.

TaskDefinition::expression()

public function expression(): string

The raw cron expression string this task was defined with, e.g. `0 3 * * *`. Callers that render a task list (Task 11's `cron:list`) use this alongside `$name`.

TaskDefinition::isDue()

public function isDue(DateTimeImmutable $now): bool

True when `$now` matches this task's cron expression. Delegates entirely to {@see CronExpression::isDue()} — this method exists so callers ({@see CronRegistry}) work against `TaskDefinition` without reaching into its expression.

Parameters

Parameters of isDue()
NameTypeDescription
$nowDateTimeImmutable