Queue Runner Overview
Goal
The queue runner coordinates how pending actions are claimed, executed, and marked complete, while respecting time and memory limits. It also schedules cleanup work and handles recurring actions.
Core flow
- Entry point:
ActionScheduler_QueueRunner::run( $context = 'WP Cron' )is invoked via WP-Cron or async requests. - Environment prep: raises memory/time limits via
ActionScheduler_Compatibility::raise_memory_limit()andActionScheduler_Compatibility::raise_time_limit(). - Hooks: fires
action_scheduler_before_process_queuebefore processing, andaction_scheduler_after_process_queueafter processing. - Cleanup:
run_cleanup()calls the queue cleaner with a time limit of10 * get_time_limit(). - Batch loop: while there are actions and limits allow, the runner:
- Claims actions via
ActionScheduler_Store::stake_claim( $batch_size ). - Processes each action with
process_action(). - Releases the claim and clears caches after the batch.
- Claims actions via
Action execution lifecycle
For each action ID, ActionScheduler_Abstract_QueueRunner::process_action():
- Installs a temporary error handler that converts recoverable errors into exceptions.
- Fires hooks in order:
action_scheduler_before_execute(always before validation)action_scheduler_execution_ignored(if notSTATUS_PENDING)action_scheduler_begin_execute(just before executing)action_scheduler_after_execute(after execution, before mark complete)
- Marks the action complete with
ActionScheduler_Store::mark_complete(). - On error:
- If the action was valid, marks failure and fires
action_scheduler_failed_execution. - If invalid, fires
action_scheduler_failed_validation.
- If the action was valid, marks failure and fires
- If the action is recurring, schedules the next instance unless it is consistently failing.
Recurring actions and failure thresholds
Recurring actions are rescheduled via ActionScheduler::factory()->repeat( $action ) unless:
- The current instance failed, and
- The recent failure threshold indicates consistent failures.
Filters and hooks:
action_scheduler_recurring_action_failure_threshold(int, default5): how many most recent actions of the same hook are checked.action_scheduler_recurring_action_is_consistently_failing(bool, default result of comparison): allow override of the assessment.action_scheduler_failed_to_schedule_next_instance: fires if repeating the action throws an exception.
Batch processing summary
Batching is controlled by:
action_scheduler_queue_runner_batch_size(int, default25inQueueRunner::run()).- Memory/time limits enforced by
batch_limits_exceeded()(seebatching.md).
Context identifiers
The run() method accepts a context string (e.g., WP Cron, Async Request, WP CLI). This context is passed to action-execution hooks so loggers and monitors can tell where actions ran.
Hooks & Filters index
Actions
action_scheduler_before_process_queueaction_scheduler_after_process_queueaction_scheduler_before_executeaction_scheduler_execution_ignoredaction_scheduler_begin_executeaction_scheduler_after_executeaction_scheduler_failed_executionaction_scheduler_failed_validationaction_scheduler_failed_to_schedule_next_instance
Filters
action_scheduler_queue_runner_classaction_scheduler_queue_runner_batch_sizeaction_scheduler_queue_runner_concurrent_batchesaction_scheduler_queue_runner_time_limitaction_scheduler_maximum_execution_time(deprecated in favor ofaction_scheduler_queue_runner_time_limit)action_scheduler_maximum_execution_time_likely_to_be_exceededaction_scheduler_memory_exceededaction_scheduler_use_cpu_execution_time