File "ActionScheduler_AsyncRequest_QueueRunner.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php
File size: 1.33 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

defined('ABSPATH') || exit;
class ActionScheduler_AsyncRequest_QueueRunner extends WP_Async_Request
{
    protected $store;
    protected $prefix = 'as';
    protected $action = 'async_request_queue_runner';
    public function __construct(ActionScheduler_Store $store)
    {
        parent::__construct();
        $this->store = $store;
    }
    protected function handle()
    {
        do_action('action_scheduler_run_queue', 'Async Request');
        $sleep_seconds = $this->get_sleep_seconds();
        if ($sleep_seconds) {
            sleep($sleep_seconds);
        }
        $this->maybe_dispatch();
    }
    public function maybe_dispatch()
    {
        if (!$this->allow()) {
            return;
        }
        $this->dispatch();
        ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request();
    }
    protected function allow()
    {
        if (!has_action('action_scheduler_run_queue') || ActionScheduler::runner()->has_maximum_concurrent_batches() || !$this->store->has_pending_actions_due()) {
            $allow = false;
        } else {
            $allow = true;
        }
        return apply_filters('action_scheduler_allow_async_request_runner', $allow);
    }
    protected function get_sleep_seconds()
    {
        return apply_filters('action_scheduler_async_request_sleep_seconds', 5, $this);
    }
}