PHP Class Automattic\WP\Cron_Control\Events

Inheritance: extends Singleton
Show file Open project: Automattic/vip-mu-plugins-public Class Usage Examples

Public Methods

Method Description
get_event ( $timestamp, $action_hashed, $instance ) Find an event's data using its hashed representations
get_events ( ) List events pending for the current period
get_lock_key_for_event_action ( $event ) : string Turn the event action into a string that can be used with a lock
prepare_environment ( ) Prepare environment to run job
run_event ( $timestamp, $action, $instance, $force = false ) : array | WP_Error Execute a specific event

Protected Methods

Method Description
class_init ( ) Register hooks

Private Methods

Method Description
action_has_callback_or_should_run_anyway ( $event ) : boolean Check that an event has a callback to run, and allow the check to be overridden Empty events are, by default, skipped and removed/rescheduled
can_run_event ( $event ) : boolean Are resources available to run this event?
do_lock_cleanup ( $event ) Free locks after event completes
prime_event_action_lock ( $event ) Prime the event-specific lock
reduce_queue ( $events ) : array Trim events queue down to the limit set by JOB_QUEUE_SIZE
reset_event_lock ( $event ) : boolean Frees the lock for an individual event
update_event_record ( $event ) Mark an event completed, and reschedule when requested

Method Details

class_init() protected method

Register hooks
protected class_init ( )

get_event() public method

The $instance argument is hashed for us by Core, while we hash the action to avoid information disclosure
public get_event ( $timestamp, $action_hashed, $instance )

get_events() public method

List events pending for the current period
public get_events ( )

get_lock_key_for_event_action() public method

Turn the event action into a string that can be used with a lock
public get_lock_key_for_event_action ( $event ) : string
$event array Event data
return string

prepare_environment() public method

Must run as early as possible, particularly before any client code is loaded This also runs before Core has parsed the request and set the \REST_REQUEST constant
public prepare_environment ( )

run_event() public method

Execute a specific event
public run_event ( $timestamp, $action, $instance, $force = false ) : array | WP_Error
$timestamp int Unix timestamp
$action string md5 hash of the action used when the event is registered
$instance string md5 hash of the event's arguments array, which Core uses to index the `cron` option
$force bool Run event regardless of timestamp or lock status? eg, when executing jobs via wp-cli
return array | WP_Error