PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 2.1.1
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v2.1.1
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 6 years ago abstracts 6 years ago actions 6 years ago data-stores 6 years ago migration 6 years ago schedules 6 years ago schema 6 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 6 years ago ActionScheduler_QueueRunner.php 6 years ago ActionScheduler_Versions.php 6 years ago ActionScheduler_WPCommentCleaner.php 6 years ago ActionScheduler_wcSystemStatus.php 6 years ago
ActionScheduler_QueueCleaner.php
156 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 ) );
48
49 foreach ( $actions_to_delete as $action_id ) {
50 try {
51 $this->store->delete_action( $action_id );
52 } catch ( Exception $e ) {
53
54 /**
55 * Notify 3rd party code of exceptions when deleting a completed action older than the retention period
56 *
57 * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their
58 * actions.
59 *
60 * @since 2.0.0
61 *
62 * @param int $action_id The scheduled actions ID in the data store
63 * @param Exception $e The exception thrown when attempting to delete the action from the data store
64 * @param int $lifespan The retention period, in seconds, for old actions
65 * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch
66 */
67 do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) );
68 }
69 }
70 }
71 }
72
73 /**
74 * Unclaim pending actions that have not been run within a given time limit.
75 *
76 * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed
77 * as a parameter is 10x the time limit used for queue processing.
78 *
79 * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes).
80 */
81 public function reset_timeouts( $time_limit = 300 ) {
82 $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit );
83 if ( $timeout < 0 ) {
84 return;
85 }
86 $cutoff = as_get_datetime_object($timeout.' seconds ago');
87 $actions_to_reset = $this->store->query_actions( array(
88 'status' => ActionScheduler_Store::STATUS_PENDING,
89 'modified' => $cutoff,
90 'modified_compare' => '<=',
91 'claimed' => true,
92 'per_page' => $this->get_batch_size(),
93 ) );
94
95 foreach ( $actions_to_reset as $action_id ) {
96 $this->store->unclaim_action( $action_id );
97 do_action( 'action_scheduler_reset_action', $action_id );
98 }
99 }
100
101 /**
102 * Mark actions that have been running for more than a given time limit as failed, based on
103 * the assumption some uncatachable and unloggable fatal error occurred during processing.
104 *
105 * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed
106 * as a parameter is 10x the time limit used for queue processing.
107 *
108 * @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).
109 */
110 public function mark_failures( $time_limit = 300 ) {
111 $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit );
112 if ( $timeout < 0 ) {
113 return;
114 }
115 $cutoff = as_get_datetime_object($timeout.' seconds ago');
116 $actions_to_reset = $this->store->query_actions( array(
117 'status' => ActionScheduler_Store::STATUS_RUNNING,
118 'modified' => $cutoff,
119 'modified_compare' => '<=',
120 'per_page' => $this->get_batch_size(),
121 ) );
122
123 foreach ( $actions_to_reset as $action_id ) {
124 $this->store->mark_failure( $action_id );
125 do_action( 'action_scheduler_failed_action', $action_id, $timeout );
126 }
127 }
128
129 /**
130 * Do all of the cleaning actions.
131 *
132 * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes).
133 * @author Jeremy Pry
134 */
135 public function clean( $time_limit = 300 ) {
136 $this->delete_old_actions();
137 $this->reset_timeouts( $time_limit );
138 $this->mark_failures( $time_limit );
139 }
140
141 /**
142 * Get the batch size for cleaning the queue.
143 *
144 * @author Jeremy Pry
145 * @return int
146 */
147 protected function get_batch_size() {
148 /**
149 * Filter the batch size when cleaning the queue.
150 *
151 * @param int $batch_size The number of actions to clean in one batch.
152 */
153 return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) );
154 }
155 }
156