ActionScheduler_QueueRunner::maybe_dispatch_async_request()publicWC 1.0

Check if we should dispatch an async request to process actions.

This method is attached to 'shutdown', so is called frequently. To avoid slowing down the site, it mitigates the work performed in each request by:

  1. checking if it's in the admin context and then
  2. haven't run on the 'shutdown' hook within the lock time (60 seconds by default)
  3. haven't exceeded the number of allowed batches.

The order of these checks is important, because they run from a check on a value:

  1. in memory - is_admin() maps to $GLOBALS or the WP_ADMIN constant
  2. in memory - transients use autoloaded options by default
  3. from a database query - has_maximum_concurrent_batches() run the query
    $this->store->get_claim_count() to find the current number of claims in the DB.

If all of these conditions are met, then we request an async runner check whether it should dispatch a request to process pending actions.

Method of the class: ActionScheduler_QueueRunner{}

No Hooks.

Return

null. Nothing (null).

Usage

$ActionScheduler_QueueRunner = new ActionScheduler_QueueRunner();
$ActionScheduler_QueueRunner->maybe_dispatch_async_request();

ActionScheduler_QueueRunner::maybe_dispatch_async_request() code WC 9.3.3

public function maybe_dispatch_async_request() {
	// Only start an async queue at most once every 60 seconds.
	if (
		is_admin()
		&& ! ActionScheduler::lock()->is_locked( 'async-request-runner' )
		&& ActionScheduler::lock()->set( 'async-request-runner' )
	) {
		$this->async_request->maybe_dispatch();
	}
}