\ActionScheduler_ActionFactory

Class ActionScheduler_ActionFactory

Summary

Methods
Properties
Constants
get_stored_action()
async()
async_unique()
single()
single_unique()
recurring()
recurring_unique()
cron()
cron_unique()
repeat()
No public properties found
No constants found
store()
store_unique_action()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

get_stored_action()

get_stored_action(string  $status, string  $hook, array  $args = array(), \ActionScheduler_Schedule  $schedule = null, string  $group = '') : \ActionScheduler_Action

Return stored actions for given params.

Parameters

string $status

The action's status in the data store.

string $hook

The hook to trigger when this action runs.

array $args

Args to pass to callbacks when the hook is triggered.

\ActionScheduler_Schedule $schedule

The action's schedule.

string $group

A group to put the action in. phpcs:ignore Squiz.Commenting.FunctionComment.ExtraParamComment

Returns

\ActionScheduler_Action —

An instance of the stored action.

async()

async(string  $hook, array  $args = array(), string  $group = '') : int

Enqueue an action to run one time, as soon as possible (rather a specific scheduled time).

This method creates a new action using the NullSchedule. In practice, this results in an action scheduled to execute "now". Therefore, it will generally run as soon as possible but is not prioritized ahead of other actions that are already past-due.

Parameters

string $hook

The hook to trigger when this action runs.

array $args

Args to pass when the hook is triggered.

string $group

A group to put the action in.

Returns

int —

The ID of the stored action.

async_unique()

async_unique(string  $hook, array  $args = array(), string  $group = '', bool  $unique = true) : int

Same as async, but also supports $unique param.

Parameters

string $hook

The hook to trigger when this action runs.

array $args

Args to pass when the hook is triggered.

string $group

A group to put the action in.

bool $unique

Whether to ensure the action is unique.

Returns

int —

The ID of the stored action.

single()

single(string  $hook, array  $args = array(), int  $when = null, string  $group = '') : int

Create single action.

Parameters

string $hook

The hook to trigger when this action runs.

array $args

Args to pass when the hook is triggered.

int $when

Unix timestamp when the action will run.

string $group

A group to put the action in.

Returns

int —

The ID of the stored action.

single_unique()

single_unique(string  $hook, array  $args = array(), int  $when = null, string  $group = '', bool  $unique = true) : int

Create single action only if there is no pending or running action with same name and params.

Parameters

string $hook

The hook to trigger when this action runs.

array $args

Args to pass when the hook is triggered.

int $when

Unix timestamp when the action will run.

string $group

A group to put the action in.

bool $unique

Whether action scheduled should be unique.

Returns

int —

The ID of the stored action.

recurring()

recurring(string  $hook, array  $args = array(), int  $first = null, int  $interval = null, string  $group = '') : int

Create the first instance of an action recurring on a given interval.

Parameters

string $hook

The hook to trigger when this action runs.

array $args

Args to pass when the hook is triggered.

int $first

Unix timestamp for the first run.

int $interval

Seconds between runs.

string $group

A group to put the action in.

Returns

int —

The ID of the stored action.

recurring_unique()

recurring_unique(string  $hook, array  $args = array(), int  $first = null, int  $interval = null, string  $group = '', bool  $unique = true) : int

Create the first instance of an action recurring on a given interval only if there is no pending or running action with same name and params.

Parameters

string $hook

The hook to trigger when this action runs.

array $args

Args to pass when the hook is triggered.

int $first

Unix timestamp for the first run.

int $interval

Seconds between runs.

string $group

A group to put the action in.

bool $unique

Whether action scheduled should be unique.

Returns

int —

The ID of the stored action.

cron()

cron(string  $hook, array  $args = array(), int  $base_timestamp = null, int  $schedule = null, string  $group = '') : int

Create the first instance of an action recurring on a Cron schedule.

Parameters

string $hook

The hook to trigger when this action runs.

array $args

Args to pass when the hook is triggered.

int $base_timestamp

The first instance of the action will be scheduled to run at a time calculated after this timestamp matching the cron expression. This can be used to delay the first instance of the action.

int $schedule

A cron definition string.

string $group

A group to put the action in.

Returns

int —

The ID of the stored action.

cron_unique()

cron_unique(string  $hook, array  $args = array(), int  $base_timestamp = null, int  $schedule = null, string  $group = '', bool  $unique = true) : int

Create the first instance of an action recurring on a Cron schedule only if there is no pending or running action with same name and params.

Parameters

string $hook

The hook to trigger when this action runs.

array $args

Args to pass when the hook is triggered.

int $base_timestamp

The first instance of the action will be scheduled to run at a time calculated after this timestamp matching the cron expression. This can be used to delay the first instance of the action.

int $schedule

A cron definition string.

string $group

A group to put the action in.

bool $unique

Whether action scheduled should be unique.

Returns

int —

The ID of the stored action.

repeat()

repeat(\ActionScheduler_Action  $action) : string

Create a successive instance of a recurring or cron action.

Importantly, the action will be rescheduled to run based on the current date/time. That means when the action is scheduled to run in the past, the next scheduled date will be pushed forward. For example, if a recurring action set to run every hour was scheduled to run 5 seconds ago, it will be next scheduled for 1 hour in the future, which is 1 hour and 5 seconds from when it was last scheduled to run.

Alternatively, if the action is scheduled to run in the future, and is run early, likely via manual intervention, then its schedule will change based on the time now. For example, if a recurring action set to run every day, and is run 12 hours early, it will run again in 24 hours, not 36 hours.

This slippage is less of an issue with Cron actions, as the specific run time can be set for them to run, e.g. 1am each day. In those cases, and entire period would need to be missed before there was any change is scheduled, e.g. in the case of an action scheduled for 1am each day, the action would need to run an entire day late.

Parameters

\ActionScheduler_Action $action

The existing action.

Throws

\InvalidArgumentException

If $action is not a recurring action.

Returns

string —

The ID of the stored action

store()

store(\ActionScheduler_Action  $action) : int

Save action to database.

Parameters

\ActionScheduler_Action $action

Action object to save.

Returns

int —

The ID of the stored action

store_unique_action()

store_unique_action(\ActionScheduler_Action  $action) : int

Store action if it's unique.

Parameters

\ActionScheduler_Action $action

Action object to store.

Returns

int —

ID of the created action. Will be 0 if action was not created.