PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 3.0.3
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v3.0.3
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes / ActionScheduler_QueueCleaner.php
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes Last commit date
WP_CLI 4 years ago abstracts 4 years ago actions 4 years ago data-stores 4 years ago migration 4 years ago schedules 4 years ago schema 4 years ago ActionScheduler_ActionClaim.php 4 years ago ActionScheduler_ActionFactory.php 4 years ago ActionScheduler_AdminView.php 4 years ago ActionScheduler_AsyncRequest_QueueRunner.php 4 years ago ActionScheduler_Compatibility.php 4 years ago ActionScheduler_DataController.php 4 years ago ActionScheduler_DateTime.php 4 years ago ActionScheduler_Exception.php 4 years ago ActionScheduler_FatalErrorMonitor.php 4 years ago ActionScheduler_InvalidActionException.php 4 years ago ActionScheduler_ListTable.php 4 years ago ActionScheduler_LogEntry.php 4 years ago ActionScheduler_NullLogEntry.php 4 years ago ActionScheduler_OptionLock.php 4 years ago ActionScheduler_QueueCleaner.php 4 years ago ActionScheduler_QueueRunner.php 4 years ago ActionScheduler_Versions.php 4 years ago ActionScheduler_WPCommentCleaner.php 4 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