HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //proc/self/cwd/wp-content/plugins/automatewoo/includes/ActionScheduler/AsyncActionRunner.php
<?php

namespace AutomateWoo\ActionScheduler;

use ActionScheduler_AsyncRequest_QueueRunner as QueueRunnerAsyncRequest;
use ActionScheduler_Lock;

defined( 'ABSPATH' ) || exit;

/**
 * Class AsyncActionRunner
 *
 * @since 5.2.0
 */
class AsyncActionRunner {

	/**
	 * Whether the shutdown hook has been attached.
	 *
	 * @var bool
	 */
	protected $has_attached_shutdown_hook = false;

	/**
	 * @var QueueRunnerAsyncRequest
	 */
	protected $async_request;

	/**
	 * @var ActionScheduler_Lock
	 */
	protected $locker;

	/**
	 * AsyncActionRunner constructor.
	 *
	 * @param QueueRunnerAsyncRequest $async_request
	 * @param ActionScheduler_Lock    $locker
	 */
	public function __construct( QueueRunnerAsyncRequest $async_request, ActionScheduler_Lock $locker ) {
		$this->async_request = $async_request;
		$this->locker        = $locker;
	}

	/**
	 * Attach async runner shutdown hook before ActionScheduler shutdown hook.
	 *
	 * The shutdown hook should only be attached if an async event has been created in the current request.
	 * The hook is only attached if it hasn't already been attached.
	 *
	 * @see ActionScheduler_QueueRunner::hook_dispatch_async_request
	 */
	public function attach_shutdown_hook() {
		if ( $this->has_attached_shutdown_hook ) {
			return;
		}

		$this->has_attached_shutdown_hook = true;
		add_action( 'shutdown', [ $this, 'maybe_dispatch_async_request' ], 9 );
	}

	/**
	 * Dispatches an async queue runner request if various conditions are met.
	 *
	 * Note: This is a temporary solution. In the future (probably ActionScheduler 3.2) we should use the filter
	 * added in https://github.com/woocommerce/action-scheduler/pull/628.
	 */
	public function maybe_dispatch_async_request() {
		if ( is_admin() ) {
			// ActionScheduler will dispatch an async runner request on it's own.
			return;
		}

		if ( $this->locker->is_locked( 'async-request-runner' ) ) {
			// An async runner request has already occurred in the last 60 seconds.
			return;
		}

		$this->locker->set( 'async-request-runner' );
		$this->async_request->maybe_dispatch();
	}

}