Batch Processing

Overview

The queue runner processes actions in batches, balancing throughput with limits on time and memory.

Batch size

Batch size controls how many actions are claimed at once:

  • Default: 25
  • Filter: action_scheduler_queue_runner_batch_size

Claiming and processing

For each batch:

  1. The runner stakes a claim with ActionScheduler_Store::stake_claim( $size ).
  2. Each action in the claim is processed with process_action().
  3. If the claim is lost during processing, the batch ends early.
  4. After the batch, the claim is released and caches are cleared.

Concurrent batch limits

The runner limits concurrent batches by checking the number of active claims:

  • action_scheduler_queue_runner_concurrent_batches (default 1)
  • ActionScheduler_Abstract_QueueRunner::has_maximum_concurrent_batches() compares current claim count to the allowed limit.

Time limits

Time limits are enforced per run:

  • Default: 30 seconds
  • Filter: action_scheduler_queue_runner_time_limit
  • Deprecated filter: action_scheduler_maximum_execution_time (use the newer filter)

The runner estimates time per action and stops the batch if it is likely to exceed the max time limit:

  • Filter: action_scheduler_maximum_execution_time_likely_to_be_exceeded
  • Optional CPU-time based measurement (e.g. Pantheon):
    • Filter: action_scheduler_use_cpu_execution_time (default defined( 'PANTHEON_ENVIRONMENT' ))

Memory limits

Memory usage is capped at 90% of the WordPress memory limit:

  • Filter: action_scheduler_memory_exceeded

If memory is exceeded, the batch stops.

Cache clearing

After each batch, caches are cleared to reduce memory and stale data:

  • Uses wp_cache_flush_runtime() when available.
  • Falls back to wp_cache_flush() if no external object cache is in use.
  • Filter action_scheduler_queue_runner_flush_cache can force flushing even with an external cache.

Hooks & Filters

Filters

  • action_scheduler_queue_runner_batch_size
  • action_scheduler_queue_runner_concurrent_batches
  • action_scheduler_queue_runner_time_limit
  • action_scheduler_maximum_execution_time (deprecated)
  • action_scheduler_maximum_execution_time_likely_to_be_exceeded
  • action_scheduler_use_cpu_execution_time
  • action_scheduler_memory_exceeded
  • action_scheduler_queue_runner_flush_cache