PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / trunk
Image Optimizer – Compress Images and Convert to WebP or AVIF vtrunk
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
← All changes | vendor/woocommerce/action-scheduler/classes/ActionScheduler_QueueRunner.php +33 -15 1.5.4 → trunk View file →
@@ -7,26 +7,41 @@
7 7 const WP_CRON_HOOK = 'action_scheduler_run_queue';
8 8
9 9 const WP_CRON_SCHEDULE = 'every_minute';
10 10
11 - /** @var ActionScheduler_AsyncRequest_QueueRunner */
11 + /**
12 + * ActionScheduler_AsyncRequest_QueueRunner instance.
13 + *
14 + * @var ActionScheduler_AsyncRequest_QueueRunner
15 + */
12 16 protected $async_request;
13 17
14 - /** @var ActionScheduler_QueueRunner */
18 + /**
19 + * ActionScheduler_QueueRunner instance.
20 + *
21 + * @var ActionScheduler_QueueRunner
22 + */
15 23 private static $runner = null;
16 24
17 - /** @var int */
25 + /**
26 + * Number of processed actions.
27 + *
28 + * @var int
29 + */
18 30 private $processed_actions_count = 0;
19 31
20 32 /**
33 + * Get instance.
34 + *
21 35 * @return ActionScheduler_QueueRunner
22 36 * @codeCoverageIgnore
23 37 */
24 38 public static function instance() {
25 - if ( empty(self::$runner) ) {
26 - $class = apply_filters('action_scheduler_queue_runner_class', 'ActionScheduler_QueueRunner');
39 + if ( empty( self::$runner ) ) {
40 + $class = apply_filters( 'action_scheduler_queue_runner_class', 'ActionScheduler_QueueRunner' );
27 41 self::$runner = new $class();
28 42 }
43 +
29 44 return self::$runner;
30 45 }
31 46
32 47 /**
@@ -31,14 +46,14 @@
31 46
32 47 /**
33 48 * ActionScheduler_QueueRunner constructor.
34 49 *
35 - * @param ActionScheduler_Store $store Store object.
36 - * @param ActionScheduler_FatalErrorMonitor $monitor Monitor object.
37 - * @param ActionScheduler_QueueCleaner $cleaner Cleaner object.
38 - * @param ActionScheduler_AsyncRequest_QueueRunner $async_request Async request runner object.
50 + * @param ActionScheduler_Store|null $store Store object.
51 + * @param ActionScheduler_FatalErrorMonitor|null $monitor Monitor object.
52 + * @param ActionScheduler_QueueCleaner|null $cleaner Cleaner object.
53 + * @param ActionScheduler_AsyncRequest_QueueRunner|null $async_request Async request runner object.
39 54 */
40 - public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null, ActionScheduler_AsyncRequest_QueueRunner $async_request = null ) {
55 + public function __construct( ?ActionScheduler_Store $store = null, ?ActionScheduler_FatalErrorMonitor $monitor = null, ?ActionScheduler_QueueCleaner $cleaner = null, ?ActionScheduler_AsyncRequest_QueueRunner $async_request = null ) {
41 56 parent::__construct( $store, $monitor, $cleaner );
42 57
43 58 if ( is_null( $async_request ) ) {
44 59 $async_request = new ActionScheduler_AsyncRequest_QueueRunner( $this->store );
@@ -47,13 +62,15 @@
47 62 $this->async_request = $async_request;
48 63 }
49 64
50 65 /**
66 + * Initialize.
67 + *
51 68 * @codeCoverageIgnore
52 69 */
53 70 public function init() {
54 71
55 - add_filter( 'cron_schedules', array( self::instance(), 'add_wp_cron_schedule' ) );
72 + add_filter( 'cron_schedules', array( self::instance(), 'add_wp_cron_schedule' ) ); // phpcs:ignore WordPress.WP.CronInterval.CronSchedulesInterval
56 73
57 74 // Check for and remove any WP Cron hook scheduled by Action Scheduler < 3.0.0, which didn't include the $context param.
58 75 $next_timestamp = wp_next_scheduled( self::WP_CRON_HOOK );
59 76 if ( $next_timestamp ) {
@@ -120,8 +137,9 @@
120 137 * The $context param of this method defaults to 'WP Cron', because prior to Action Scheduler 3.0.0
121 138 * that was the only context in which this method was run, and the self::WP_CRON_HOOK hook had no context
122 139 * passed along with it. New code calling this method directly, or by triggering the self::WP_CRON_HOOK,
123 140 * should set a context as the first parameter. For an example of this, refer to the code seen in
141 + *
124 142 * @see ActionScheduler_AsyncRequest_QueueRunner::handle()
125 143 *
126 144 * @param string $context Optional identifier for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
127 145 * Generally, this should be capitalised and not localised as it's a proper noun.
@@ -157,15 +175,15 @@
157 175 * Generally, this should be capitalised and not localised as it's a proper noun.
158 176 * @return int The number of actions processed.
159 177 */
160 178 protected function do_batch( $size = 100, $context = '' ) {
161 - $claim = $this->store->stake_claim($size);
162 - $this->monitor->attach($claim);
179 + $claim = $this->store->stake_claim( $size );
180 + $this->monitor->attach( $claim );
163 181 $processed_actions = 0;
164 182
165 183 foreach ( $claim->get_actions() as $action_id ) {
166 184 // bail if we lost the claim.
167 - if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ) ) ) {
185 + if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ), true ) ) {
168 186 break;
169 187 }
170 188 $this->process_action( $action_id, $context );
171 189 $processed_actions++;
@@ -173,9 +191,9 @@
173 191 if ( $this->batch_limits_exceeded( $processed_actions + $this->processed_actions_count ) ) {
174 192 break;
175 193 }
176 194 }
177 - $this->store->release_claim($claim);
195 + $this->store->release_claim( $claim );
178 196 $this->monitor->detach();
179 197 $this->clear_caches();
180 198 return $processed_actions;
181 199 }