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/abstracts/ActionScheduler_Abstract_QueueRunner.php +33 -22 1.0.2 → trunk View file →
@@ -4,15 +4,27 @@
4 4 * Abstract class with common Queue Cleaner functionality.
5 5 */
6 6 abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abstract_QueueRunner_Deprecated {
7 7
8 - /** @var ActionScheduler_QueueCleaner */
8 + /**
9 + * ActionScheduler_QueueCleaner instance.
10 + *
11 + * @var ActionScheduler_QueueCleaner
12 + */
9 13 protected $cleaner;
10 14
11 - /** @var ActionScheduler_FatalErrorMonitor */
15 + /**
16 + * ActionScheduler_FatalErrorMonitor instance.
17 + *
18 + * @var ActionScheduler_FatalErrorMonitor
19 + */
12 20 protected $monitor;
13 21
14 - /** @var ActionScheduler_Store */
22 + /**
23 + * ActionScheduler_Store instance.
24 + *
25 + * @var ActionScheduler_Store
26 + */
15 27 protected $store;
16 28
17 29 /**
18 30 * The created time.
@@ -26,13 +38,13 @@
26 38
27 39 /**
28 40 * ActionScheduler_Abstract_QueueRunner constructor.
29 41 *
30 - * @param ActionScheduler_Store $store
31 - * @param ActionScheduler_FatalErrorMonitor $monitor
32 - * @param ActionScheduler_QueueCleaner $cleaner
42 + * @param ActionScheduler_Store|null $store Store object.
43 + * @param ActionScheduler_FatalErrorMonitor|null $monitor Monitor object.
44 + * @param ActionScheduler_QueueCleaner|null $cleaner Cleaner object.
33 45 */
34 - public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) {
46 + public function __construct( ?ActionScheduler_Store $store = null, ?ActionScheduler_FatalErrorMonitor $monitor = null, ?ActionScheduler_QueueCleaner $cleaner = null ) {
35 47
36 48 $this->created_time = microtime( true );
37 49
38 50 $this->store = $store ? $store : ActionScheduler_Store::instance();
@@ -42,17 +54,19 @@
42 54
43 55 /**
44 56 * Process an individual action.
45 57 *
46 - * @param int $action_id The action ID to process.
47 - * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
48 - * Generally, this should be capitalised and not localised as it's a proper noun.
58 + * @param int $action_id The action ID to process.
59 + * @param string $context Optional identifier for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
60 + * Generally, this should be capitalised and not localised as it's a proper noun.
61 + * @throws \Exception When error running action.
49 62 */
50 63 public function process_action( $action_id, $context = '' ) {
51 64 // Temporarily override the error handler while we process the current action.
65 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler
52 66 set_error_handler(
53 67 /**
54 - * Temporary error handler which can catch errors and convert them into exceptions. This faciliates more
68 + * Temporary error handler which can catch errors and convert them into exceptions. This facilitates more
55 69 * robust error handling across all supported PHP versions.
56 70 *
57 71 * @throws Exception
58 72 *
@@ -140,10 +154,10 @@
140 154
141 155 /**
142 156 * Schedule the next instance of the action if necessary.
143 157 *
144 - * @param ActionScheduler_Action $action
145 - * @param int $action_id
158 + * @param ActionScheduler_Action $action Action.
159 + * @param int $action_id Action ID.
146 160 */
147 161 protected function schedule_next_instance( ActionScheduler_Action $action, $action_id ) {
148 162 // If a recurring action has been consistently failing, we may wish to stop rescheduling it.
149 163 if (
@@ -191,9 +205,9 @@
191 205 'status' => ActionScheduler_Store::STATUS_FAILED,
192 206 'date' => date_create( 'now', timezone_open( 'UTC' ) )->format( 'Y-m-d H:i:s' ),
193 207 'date_compare' => '<',
194 208 'per_page' => 1,
195 - 'offset' => $consistent_failure_threshold - 1
209 + 'offset' => $consistent_failure_threshold - 1,
196 210 );
197 211
198 212 $first_failing_action_id = $this->store->query_actions( $query_args );
199 213
@@ -221,10 +235,8 @@
221 235 }
222 236
223 237 /**
224 238 * Run the queue cleaner.
225 - *
226 - * @author Jeremy Pry
227 239 */
228 240 protected function run_cleanup() {
229 241 $this->cleaner->clean( 10 * $this->get_time_limit() );
230 242 }
@@ -255,9 +267,9 @@
255 267 protected function get_time_limit() {
256 268
257 269 $time_limit = 30;
258 270
259 - // Apply deprecated filter from deprecated get_maximum_execution_time() method
271 + // Apply deprecated filter from deprecated get_maximum_execution_time() method.
260 272 if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) {
261 273 _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' );
262 274 $time_limit = apply_filters( 'action_scheduler_maximum_execution_time', $time_limit );
263 275 }
@@ -287,9 +299,9 @@
287 299
288 300 /**
289 301 * Check if the host's max execution time is (likely) to be exceeded if processing more actions.
290 302 *
291 - * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action
303 + * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action.
292 304 * @return bool
293 305 */
294 306 protected function time_likely_to_be_exceeded( $processed_actions ) {
295 307 $execution_time = $this->get_execution_time();
@@ -317,9 +329,9 @@
317 329 protected function get_memory_limit() {
318 330 if ( function_exists( 'ini_get' ) ) {
319 331 $memory_limit = ini_get( 'memory_limit' );
320 332 } else {
321 - $memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce
333 + $memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce.
322 334 }
323 335
324 336 if ( ! $memory_limit || -1 === $memory_limit || '-1' === $memory_limit ) {
325 337 // Unlimited, set to 32GB.
@@ -352,9 +364,9 @@
352 364 * the maximum limit, or the time to process more actions will exceed the max time limit.
353 365 *
354 366 * Based on WC_Background_Process::batch_limits_exceeded()
355 367 *
356 - * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action
368 + * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action.
357 369 * @return bool
358 370 */
359 371 protected function batch_limits_exceeded( $processed_actions ) {
360 372 return $this->memory_exceeded() || $this->time_likely_to_be_exceeded( $processed_actions );
@@ -362,10 +374,9 @@
362 374
363 375 /**
364 376 * Process actions in the queue.
365 377 *
366 - * @author Jeremy Pry
367 - * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
378 + * @param string $context Optional identifier for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
368 379 * Generally, this should be capitalised and not localised as it's a proper noun.
369 380 * @return int The number of actions processed.
370 381 */
371 382 abstract public function run( $context = '' );