class Task (View source)

Constants

MODE_CRON

MODE_INTERVAL

MODE_ONCE

Methods

__construct(callable $callback)

Create a Task instance

cron(int|string $minute, int|string $hour, int|string $day, int|string $month, int|string $weekday)

Schedule the task using crontab-like fields.

interval(int $seconds)

Schedule the task to run repeatedly every given number of seconds, counted from its last execution.

once(DateTime $datetime)

Schedule the task to run exactly once, at (or after) the given date/time.

at(int|string $hour, int|string $minute)

Shortcut for scheduling the task to run daily at a fixed time.

runInBackground(bool $enable = true)

Marks this task to be dispatched as a detached background process instead of running synchronously within the scheduler process.

bool
isBackground()

Whether this task should be dispatched as a detached background process

runInEnvironments(array $environments)

Configure the environments in which this task should be dispatched when the APP_ENVIRONMENT environment variable matches.

bool
isDue(DateTime $now, int|null $lastRun)

Checks whether the task is due to run now, given the last time it ran

int
run()

Executes the task's callback

Details

__construct(callable $callback)

Create a Task instance

Parameters

callable $callback

Task cron(int|string $minute, int|string $hour, int|string $day, int|string $month, int|string $weekday)

Schedule the task using crontab-like fields.

Note: Each field accepts: * (any), a single value, a comma-separated list (1,2,5), a range (1-5), a step (*\/5 or 1-30/5), or a combination of these separated by commas.

Parameters

int|string $minute 0-59
int|string $hour 0-23
int|string $day 1-31
int|string $month 1-12
int|string $weekday

0-7 (0 and 7 both mean Sunday)

Return Value

Task

Exceptions

Exception

Task interval(int $seconds)

Schedule the task to run repeatedly every given number of seconds, counted from its last execution.

Parameters

int $seconds

Return Value

Task

Exceptions

Exception

Task once(DateTime $datetime)

Schedule the task to run exactly once, at (or after) the given date/time.

Once executed, it will never run again.

Parameters

DateTime $datetime

Return Value

Task

Task at(int|string $hour, int|string $minute)

Shortcut for scheduling the task to run daily at a fixed time.

Equivalent to cron($minute, $hour, '*', '*', '*').

Parameters

int|string $hour
int|string $minute

Return Value

Task

Exceptions

Exception

Task runInBackground(bool $enable = true)

Marks this task to be dispatched as a detached background process instead of running synchronously within the scheduler process.

Parameters

bool $enable

Return Value

Task

Exceptions

Exception

bool isBackground()

Whether this task should be dispatched as a detached background process

Return Value

bool

Task runInEnvironments(array $environments)

Configure the environments in which this task should be dispatched when the APP_ENVIRONMENT environment variable matches.

Parameters

array $environments

Return Value

Task

bool isDue(DateTime $now, int|null $lastRun)

Checks whether the task is due to run now, given the last time it ran

Parameters

DateTime $now
int|null $lastRun

Unix timestamp of the last execution, or null if it never ran

Return Value

bool

Exceptions

Exception

int run()

Executes the task's callback

Return Value

int

Exceptions

Exception