-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schedule next action before current one is mark completed/failed. #830
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,16 +64,26 @@ public function process_action( $action_id, $context = '' ) { | |
$this->store->log_execution( $action_id ); | ||
$action->execute(); | ||
do_action( 'action_scheduler_after_execute', $action_id, $action, $context ); | ||
$this->maybe_schedule_next_instance( $action, $action_id ); | ||
$this->store->mark_complete( $action_id ); | ||
} catch ( Exception $e ) { | ||
if ( $valid_action ) { | ||
$this->maybe_schedule_next_instance( $action, $action_id ); | ||
$this->store->mark_failure( $action_id ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking of PR #806, it may be better to wait until the action has been marked as a failure before we call |
||
do_action( 'action_scheduler_failed_execution', $action_id, $e, $context ); | ||
} else { | ||
do_action( 'action_scheduler_failed_validation', $action_id, $e, $context ); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Helper method to schedule next instance of an instance if there is a schedule. | ||
* | ||
* @param ActionScheduler_Action $action Action object. | ||
* @param int $action_id Action ID. | ||
*/ | ||
private function maybe_schedule_next_instance( $action, $action_id ) { | ||
if ( isset( $action ) && is_a( $action, 'ActionScheduler_Action' ) && $action->get_schedule()->is_recurring() ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does testing if |
||
$this->schedule_next_instance( $action, $action_id ); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotated this block with comments at the end of each line:
↑ This chain of events seems unlikely, but still technically possible and could result in a duplicate.