Schedule next action before current one is mark completed/failed.#830
Open
vedanshujain wants to merge 1 commit into
Open
Schedule next action before current one is mark completed/failed.#830vedanshujain wants to merge 1 commit into
vedanshujain wants to merge 1 commit into
Conversation
This prevents race condition that may happen if we are trying to schedule same action, and the check `as_has_scheduled_action` runs after action is marked complete but before next one is scheduled.
barryhughes
reviewed
Jun 20, 2022
Comment on lines
+67
to
+71
| $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 ); |
Member
There was a problem hiding this comment.
Annotated this block with comments at the end of each line:
$this->maybe_schedule_next_instance( $action, $action_id ); # 1. Next instance is scheduled
$this->store->mark_complete( $action_id ); # 2. Exception can be thrown by this method
} catch ( Exception $e ) { # 3. Execution enters the catch block
if ( $valid_action ) { # 4. Action still 'valid'
$this->maybe_schedule_next_instance( $action, $action_id ); # 5. We schedule another instance↑ This chain of events seems unlikely, but still technically possible and could result in a duplicate.
| } catch ( Exception $e ) { | ||
| if ( $valid_action ) { | ||
| $this->maybe_schedule_next_instance( $action, $action_id ); | ||
| $this->store->mark_failure( $action_id ); |
Member
There was a problem hiding this comment.
Thinking of PR #806, it may be better to wait until the action has been marked as a failure before we call ::maybe_schedule_next_instance() (though, if this is merged first we can also update that other PR accordingly).
barryhughes
reviewed
Jun 20, 2022
| * @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() ) { |
Member
There was a problem hiding this comment.
Does testing if $action is set still make sense, now this is in its own method?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This prevents race conditions that may happen if we are trying to schedule the same action, and the check
as_has_scheduled_actionruns after the action is marked complete but before the next one is scheduled.Fixes #698