Skip to content
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

check both stores for an action while migration is in progress #489

Merged
merged 3 commits into from Apr 22, 2020

Conversation

rrennick
Copy link
Collaborator

@rrennick rrennick commented Mar 12, 2020

Closes #486

This PR updates the Hybrid data store to use the primary & secondary data stores' fetch_action to determine whether an action ID exists in that store before using the store to retrieve action data. Both data stores implement exception handling in fetch_action and return a NullAction action when the action is not found/valid.

  • Determine the minimum action ID in the tables data store SELECT MIN(action_id) FROM wp_actionscheduler_actions;
  • Ensure your migration is complete
  • Create a number of pending actions
add_action( 'init', function() {
	for ( $i = 1; $i < 200; $i++ )
	as_enqueue_async_action( 'as-async-test' . $i );
} );
  • Add a log to check that actions are being processed before the migration action is processed
add_action( 'action_scheduler_after_execute', function( $action_id, $action ) {
	error_log( $action->get_hook() );
}, 10, 2 );
  • Update your demarkation ID to be 10000 greater than the maximum action_id in the actions table
    wp option update action_scheduler_hybrid_store_demarkation 123456
  • Reset the migration complete flag wp option delete action_scheduler_migration_status
  • Load the Tools -> Scheduled Actions screen
  • Check the Pending/Completed list for the test actions to be processed
  • Migration should complete
  • No errors or warnings should be logged

@rrennick
Copy link
Collaborator Author

@thenbrent Could you give this one a sanity check where I added null return values?

@rrennick rrennick added this to the 3.1.3 milestone Mar 12, 2020
@thenbrent
Copy link
Contributor

This is a bit of a dangerous change, but it looks good @rrennick. I like the introduction of a central get_store_from_action_id() method.

The reason I says it's a dangerous changes is because prior to this patch, if an action had an $action_id < $this->demarkation_id, it had to exist in the old, post data store for it to be run. Now it can exist in either and still be run.

Processing actions under new conditions creates the risk of processing an action when it shouldn't be run. I can't see any conditions where this would cause a problem. Even when considering corner-cases like upgrade-downgrade-upgrade. However, I want to mention the risk as it should be considered before merging.

@becdetat
Copy link

I'm unqualified to talk about the risk but I followed the instructions and I'm pretty sure it tested ok.

@rrennick
Copy link
Collaborator Author

Now it can exist in either and still be run.

@thenbrent Thanks, good point.

@becdetat Thanks for the feedback :)

@rrennick rrennick added status: in progress This is being worked on. and removed Status: Needs Review labels Mar 13, 2020
@rrennick rrennick modified the milestones: 3.1.3, 3.2.0 Mar 13, 2020
@rrennick rrennick added Status: Needs Review and removed status: in progress This is being worked on. labels Mar 31, 2020
@rrennick rrennick modified the milestones: 3.2.0, 3.1.5 Mar 31, 2020
@rrennick
Copy link
Collaborator Author

@jeffstieler This is ready for a review.

Copy link
Contributor

@jeffstieler jeffstieler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tested well with the provided instructions, but there seems to be some copy-pasta in the get_store_from_action_id() logic.

AS only uses the hybrid store fetch_action in the queue runners and the list table.
The hybrid store claims actions for the queue runners from the primary store.
The flag ensures that the queue runner receives actions from the primary store
in the event of a duplicate action ID.
If there is a duplicate action ID between stores, the secondary store one will be
inaccessible in the list table until it is migrated.
@rrennick
Copy link
Collaborator Author

rrennick commented Apr 2, 2020

@jeffstieler This is ready for another review.

Copy link
Contributor

@jeffstieler jeffstieler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good and (still) tests well. :shipit:

@rrennick rrennick merged commit cffcb29 into master Apr 22, 2020
@rrennick rrennick deleted the issue_486 branch April 22, 2020 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncaught InvalidArgumentException in system status
4 participants