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

  1. Entry point: ActionScheduler_QueueRunner::run( $context = 'WP Cron' ) is invoked via WP-Cron or async requests.
  2. Environment prep: raises memory/time limits via ActionScheduler_Compatibility::raise_memory_limit() and ActionScheduler_Compatibility::raise_time_limit().
  3. Hooks: fires action_scheduler_before_process_queue before processing, and action_scheduler_after_process_queue after processing.
  4. Cleanup: run_cleanup() calls the queue cleaner with a time limit of 10 * get_time_limit().
  5. 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.

Action execution lifecycle

For each action ID, ActionScheduler_Abstract_QueueRunner::process_action():

  1. Installs a temporary error handler that converts recoverable errors into exceptions.
  2. Fires hooks in order:
    • action_scheduler_before_execute (always before validation)
    • action_scheduler_execution_ignored (if not STATUS_PENDING)
    • action_scheduler_begin_execute (just before executing)
    • action_scheduler_after_execute (after execution, before mark complete)
  3. Marks the action complete with ActionScheduler_Store::mark_complete().
  4. On error:
    • If the action was valid, marks failure and fires action_scheduler_failed_execution.
    • If invalid, fires action_scheduler_failed_validation.
  5. 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, default 5): 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, default 25 in QueueRunner::run()).
  • Memory/time limits enforced by batch_limits_exceeded() (see batching.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_queue
  • action_scheduler_after_process_queue
  • action_scheduler_before_execute
  • action_scheduler_execution_ignored
  • action_scheduler_begin_execute
  • action_scheduler_after_execute
  • action_scheduler_failed_execution
  • action_scheduler_failed_validation
  • action_scheduler_failed_to_schedule_next_instance

Filters

  • action_scheduler_queue_runner_class
  • action_scheduler_queue_runner_batch_size
  • action_scheduler_queue_runner_concurrent_batches
  • action_scheduler_queue_runner_time_limit
  • action_scheduler_maximum_execution_time (deprecated in favor of action_scheduler_queue_runner_time_limit)
  • action_scheduler_maximum_execution_time_likely_to_be_exceeded
  • action_scheduler_memory_exceeded
  • action_scheduler_use_cpu_execution_time