ActionScheduler_Abstract_QueueRunner::recurring_action_is_consistently_failing()
Determine if the specified recurring action has been consistently failing.
Метод класса: ActionScheduler_Abstract_QueueRunner{}
Хуки из метода
Возвращает
true|false
.
Использование
// private - только в коде основоного (родительского) класса $result = $this->recurring_action_is_consistently_failing( $action, $action_id );
- $action(ActionScheduler_Action) (обязательный)
- The recurring action to be rescheduled.
- $action_id(int) (обязательный)
- The ID of the recurring action.
Код ActionScheduler_Abstract_QueueRunner::recurring_action_is_consistently_failing() ActionScheduler Abstract QueueRunner::recurring action is consistently failing WC 7.7.2
private function recurring_action_is_consistently_failing( ActionScheduler_Action $action, $action_id ) { /** * Controls the failure threshold for recurring actions. * * Before rescheduling a recurring action, we look at its status. If it failed, we then check if all of the most * recent actions (upto the threshold set by this filter) sharing the same hook have also failed: if they have, * that is considered consistent failure and a new instance of the action will not be scheduled. * * @param int $failure_threshold Number of actions of the same hook to examine for failure. Defaults to 5. */ $consistent_failure_threshold = (int) apply_filters( 'action_scheduler_recurring_action_failure_threshold', 5 ); // This query should find the earliest *failing* action (for the hook we are interested in) within our threshold. $query_args = array( 'hook' => $action->get_hook(), 'status' => ActionScheduler_Store::STATUS_FAILED, 'date' => date_create( 'now', timezone_open( 'UTC' ) )->format( 'Y-m-d H:i:s' ), 'date_compare' => '<', 'per_page' => 1, 'offset' => $consistent_failure_threshold - 1 ); $first_failing_action_id = $this->store->query_actions( $query_args ); // If we didn't retrieve an action ID, then there haven't been enough failures for us to worry about. if ( empty( $first_failing_action_id ) ) { return false; } // Now let's fetch the first action (having the same hook) of *any status*ithin the same window. unset( $query_args['status'] ); $first_action_id_with_the_same_hook = $this->store->query_actions( $query_args ); // If the IDs match, then actions for this hook must be consistently failing. return $first_action_id_with_the_same_hook === $first_failing_action_id; }