mailpoet
/
vendor
/
woocommerce
/
action-scheduler
/
classes
/
ActionScheduler_AsyncRequest_QueueRunner.php
WP_CLI
1 year ago
abstracts
1 year ago
actions
1 year ago
data-stores
1 year ago
migration
1 year ago
schedules
1 year ago
schema
1 year ago
ActionScheduler_ActionClaim.php
1 year ago
ActionScheduler_ActionFactory.php
1 year ago
ActionScheduler_AdminView.php
1 year ago
ActionScheduler_AsyncRequest_QueueRunner.php
1 year ago
ActionScheduler_Compatibility.php
1 year ago
ActionScheduler_DataController.php
1 year ago
ActionScheduler_DateTime.php
1 year ago
ActionScheduler_Exception.php
4 years ago
ActionScheduler_FatalErrorMonitor.php
1 year ago
ActionScheduler_InvalidActionException.php
1 year ago
ActionScheduler_ListTable.php
1 year ago
ActionScheduler_LogEntry.php
1 year ago
ActionScheduler_NullLogEntry.php
1 year ago
ActionScheduler_OptionLock.php
2 years ago
ActionScheduler_QueueCleaner.php
1 year ago
ActionScheduler_QueueRunner.php
1 year ago
ActionScheduler_SystemInformation.php
1 year ago
ActionScheduler_Versions.php
1 year ago
ActionScheduler_WPCommentCleaner.php
1 year ago
ActionScheduler_wcSystemStatus.php
4 years ago
index.php
3 years ago
ActionScheduler_AsyncRequest_QueueRunner.php
39 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | defined( 'ABSPATH' ) || exit; |
| 4 | class ActionScheduler_AsyncRequest_QueueRunner extends WP_Async_Request { |
| 5 | protected $store; |
| 6 | protected $prefix = 'as'; |
| 7 | protected $action = 'async_request_queue_runner'; |
| 8 | public function __construct( ActionScheduler_Store $store ) { |
| 9 | parent::__construct(); |
| 10 | $this->store = $store; |
| 11 | } |
| 12 | protected function handle() { |
| 13 | do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context. |
| 14 | $sleep_seconds = $this->get_sleep_seconds(); |
| 15 | if ( $sleep_seconds ) { |
| 16 | sleep( $sleep_seconds ); |
| 17 | } |
| 18 | $this->maybe_dispatch(); |
| 19 | } |
| 20 | public function maybe_dispatch() { |
| 21 | if ( ! $this->allow() ) { |
| 22 | return; |
| 23 | } |
| 24 | $this->dispatch(); |
| 25 | ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); |
| 26 | } |
| 27 | protected function allow() { |
| 28 | if ( ! has_action( 'action_scheduler_run_queue' ) || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due() ) { |
| 29 | $allow = false; |
| 30 | } else { |
| 31 | $allow = true; |
| 32 | } |
| 33 | return apply_filters( 'action_scheduler_allow_async_request_runner', $allow ); |
| 34 | } |
| 35 | protected function get_sleep_seconds() { |
| 36 | return apply_filters( 'action_scheduler_async_request_sleep_seconds', 5, $this ); |
| 37 | } |
| 38 | } |
| 39 |