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3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / packages / action-scheduler / classes / ActionScheduler_QueueCleaner.php
woocommerce / packages / action-scheduler / classes Last commit date
WP_CLI 6 years ago abstracts 4 years ago actions 4 years ago data-stores 4 years ago migration 4 years ago schedules 6 years ago schema 4 years ago ActionScheduler_ActionClaim.php 6 years ago ActionScheduler_ActionFactory.php 6 years ago ActionScheduler_AdminView.php 6 years ago ActionScheduler_AsyncRequest_QueueRunner.php 6 years ago ActionScheduler_Compatibility.php 6 years ago ActionScheduler_DataController.php 6 years ago ActionScheduler_DateTime.php 6 years ago ActionScheduler_Exception.php 6 years ago ActionScheduler_FatalErrorMonitor.php 6 years ago ActionScheduler_InvalidActionException.php 6 years ago ActionScheduler_ListTable.php 6 years ago ActionScheduler_LogEntry.php 6 years ago ActionScheduler_NullLogEntry.php 6 years ago ActionScheduler_OptionLock.php 6 years ago ActionScheduler_QueueCleaner.php 4 years ago ActionScheduler_QueueRunner.php 6 years ago ActionScheduler_Versions.php 6 years ago ActionScheduler_WPCommentCleaner.php 6 years ago ActionScheduler_wcSystemStatus.php 4 years ago
ActionScheduler_QueueCleaner.php
159 lines
1 <?php
2
3 /**
4 * Class ActionScheduler_QueueCleaner
5 */
6 class ActionScheduler_QueueCleaner {
7
8 /** @var int */
9 protected $batch_size;
10
11 /** @var ActionScheduler_Store */
12 private $store = null;
13
14 /**
15 * 31 days in seconds.
16 *
17 * @var int
18 */
19 private $month_in_seconds = 2678400;
20
21 /**
22 * ActionScheduler_QueueCleaner constructor.
23 *
24 * @param ActionScheduler_Store $store The store instance.
25 * @param int $batch_size The batch size.
26 */
27 public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) {
28 $this->store = $store ? $store : ActionScheduler_Store::instance();
29 $this->batch_size = $batch_size;
30 }
31
32 public function delete_old_actions() {
33 $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds );
34 $cutoff = as_get_datetime_object($lifespan.' seconds ago');
35
36 $statuses_to_purge = array(
37 ActionScheduler_Store::STATUS_COMPLETE,
38 ActionScheduler_Store::STATUS_CANCELED,
39 );
40
41 foreach ( $statuses_to_purge as $status ) {
42 $actions_to_delete = $this->store->query_actions( array(
43 'status' => $status,
44 'modified' => $cutoff,
45 'modified_compare' => '<=',
46 'per_page' => $this->get_batch_size(),
47 'orderby' => 'none',
48 ) );
49
50 foreach ( $actions_to_delete as $action_id ) {
51 try {
52 $this->store->delete_action( $action_id );
53 } catch ( Exception $e ) {
54
55 /**
56 * Notify 3rd party code of exceptions when deleting a completed action older than the retention period
57 *
58 * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their
59 * actions.
60 *
61 * @since 2.0.0
62 *
63 * @param int $action_id The scheduled actions ID in the data store
64 * @param Exception $e The exception thrown when attempting to delete the action from the data store
65 * @param int $lifespan The retention period, in seconds, for old actions
66 * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch
67 */
68 do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) );
69 }
70 }
71 }
72 }
73
74 /**
75 * Unclaim pending actions that have not been run within a given time limit.
76 *
77 * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed
78 * as a parameter is 10x the time limit used for queue processing.
79 *
80 * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes).
81 */
82 public function reset_timeouts( $time_limit = 300 ) {
83 $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit );
84 if ( $timeout < 0 ) {
85 return;
86 }
87 $cutoff = as_get_datetime_object($timeout.' seconds ago');
88 $actions_to_reset = $this->store->query_actions( array(
89 'status' => ActionScheduler_Store::STATUS_PENDING,
90 'modified' => $cutoff,
91 'modified_compare' => '<=',
92 'claimed' => true,
93 'per_page' => $this->get_batch_size(),
94 'orderby' => 'none',
95 ) );
96
97 foreach ( $actions_to_reset as $action_id ) {
98 $this->store->unclaim_action( $action_id );
99 do_action( 'action_scheduler_reset_action', $action_id );
100 }
101 }
102
103 /**
104 * Mark actions that have been running for more than a given time limit as failed, based on
105 * the assumption some uncatachable and unloggable fatal error occurred during processing.
106 *
107 * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed
108 * as a parameter is 10x the time limit used for queue processing.
109 *
110 * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes).
111 */
112 public function mark_failures( $time_limit = 300 ) {
113 $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit );
114 if ( $timeout < 0 ) {
115 return;
116 }
117 $cutoff = as_get_datetime_object($timeout.' seconds ago');
118 $actions_to_reset = $this->store->query_actions( array(
119 'status' => ActionScheduler_Store::STATUS_RUNNING,
120 'modified' => $cutoff,
121 'modified_compare' => '<=',
122 'per_page' => $this->get_batch_size(),
123 'orderby' => 'none',
124 ) );
125
126 foreach ( $actions_to_reset as $action_id ) {
127 $this->store->mark_failure( $action_id );
128 do_action( 'action_scheduler_failed_action', $action_id, $timeout );
129 }
130 }
131
132 /**
133 * Do all of the cleaning actions.
134 *
135 * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes).
136 * @author Jeremy Pry
137 */
138 public function clean( $time_limit = 300 ) {
139 $this->delete_old_actions();
140 $this->reset_timeouts( $time_limit );
141 $this->mark_failures( $time_limit );
142 }
143
144 /**
145 * Get the batch size for cleaning the queue.
146 *
147 * @author Jeremy Pry
148 * @return int
149 */
150 protected function get_batch_size() {
151 /**
152 * Filter the batch size when cleaning the queue.
153 *
154 * @param int $batch_size The number of actions to clean in one batch.
155 */
156 return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) );
157 }
158 }
159