Async HTTP Request Queue Runner

Overview

ActionScheduler_AsyncRequest_QueueRunner extends WP_Async_Request to run the queue via a non-blocking HTTP request. This provides a fallback and a way to process actions when WP-Cron is delayed.

When async requests are dispatched

The main queue runner calls maybe_dispatch_async_request() during shutdown:

  • It only runs in the admin context (is_admin()).
  • It uses a lock to ensure the async runner is only triggered once per lock duration.
  • It avoids expensive DB checks if possible.

Locking details are in locking.md.

Dispatch flow

  1. ActionScheduler_QueueRunner::maybe_dispatch_async_request() verifies:
    • is_admin()
    • ActionScheduler::lock()->is_locked( 'async-request-runner' ) is false
    • ActionScheduler::lock()->set( 'async-request-runner' ) succeeds
  2. If all checks pass, it calls $this->async_request->maybe_dispatch().

Async request handling

ActionScheduler_AsyncRequest_QueueRunner::handle():

  1. Fires do_action( 'action_scheduler_run_queue', 'Async Request' ) to run a queue with Async Request context.
  2. Sleeps briefly to avoid MySQL crashes when chaining async requests:
    • action_scheduler_async_request_sleep_seconds (default 5)
  3. Calls maybe_dispatch() again to chain another request if needed.

Allowing or disabling async requests

ActionScheduler_AsyncRequest_QueueRunner::allow() permits dispatch only if:

  • action_scheduler_run_queue has a hooked handler
  • The runner does not already have maximum concurrent batches
  • There are pending actions due in the store

Then it passes the decision through:

  • action_scheduler_allow_async_request_runner (bool)

Hooks & Filters

Actions

  • action_scheduler_run_queue (invoked with context Async Request)

Filters

  • action_scheduler_allow_async_request_runner
  • action_scheduler_async_request_sleep_seconds