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

add bulk cancel by hook/group to table store #351

Merged
merged 7 commits into from
Sep 3, 2019
Merged

Conversation

rrennick
Copy link
Contributor

This PR adds two bulk cancel functions to the table data store with a unit test for each function

  • cancel_actions_by_group( $group_slug ) cancels pending actions by group
  • cancel_actions_by_hook( $hook_name ) cancels pending actions by hook

This is a prerequisite for woocommerce/woocommerce-admin#2766 to allow bulk cancelation of pending actions.

In future, other plugins using AS will also be able to take advantage of these function to cancel their pending actions on de-activation.

@rrennick rrennick added custom-tables type: enhancement The issue is a request for an enhancement. labels Aug 12, 2019
@rrennick rrennick added this to the 3.0.0 milestone Aug 12, 2019
@rrennick
Copy link
Contributor Author

@thenbrent The test failure was a travis download/install error. I don't have the option to restart the test.

@thenbrent
Copy link
Contributor

@rrennick this is looking good. I think it needs a few additions though:

  1. the cancellation log even should still be logged on these actions, even if they're "bulk cancelled", otherwise, we won't be able to trace their history.
  2. ideally, these methods should be added to the base ActionScheduler_Store class too, and implemented using loops, so there is a default implementation across all data stores
  3. as_unschedule_all_actions() should be updated to use these new methods when possible, thanks to the perf improvements that come from them.

@rrennick
Copy link
Contributor Author

the cancellation log even should still be logged on these actions, even if they're "bulk cancelled", otherwise, we won't be able to trace their history.

In WC Admin, we opted to cancel the actions and allow them to be removed by the auto purge in Action Scheduler instead of deleting the actions as changing the status could be done with a single query. For the purposes of plugin deactivation I think it would be better to provide a method of deleting any related pending actions than cancelling and adding log entries.

@thenbrent
Copy link
Contributor

For the purposes of plugin deactivation I think it would be better to provide a method of deleting any related pending actions than cancelling and adding log entries.

I was thinking about this issue when fixing recurring schedules.

The persistence of recurring actions after deactivating the plugin which created and required them is a strong argument for removing recurring schedules completely.

If all actions where "single", and any successive action needed to be rescheduled by the plugin using it, based on the when the prior one ran, they would automatically be cease to recur once that plugin was deactivated and wouldn't need to be cancelled.

This is mostly moot now because I went the route of fixing schedules, but I'm noting it as an alternative approach.

I still think having a log is important to help trace the reason for the cancellation (and time/date).

@rrennick
Copy link
Contributor Author

@thenbrent Can you restart the one test that failed? It ran right about midnight UTC, so tomorrow could have been in 30 seconds and subtracting the minute put $date in the past.

If that test passes, this is ready for re-review.

By implementing fallback logging methods, and making sure the
'action_scheduler_bulk_cancel_actions' hook is called when using
the fallback ActionScheduler_Store::cancel_actions_by_* methods.
@thenbrent
Copy link
Contributor

This LGTM.

I added SHA: 76e149d to provide logging for bulk cancellation done via the ActionScheduler_Store fallback methods. Tests are still passing, so merging now so we can tag 3.0.0-beta-1.

@thenbrent thenbrent merged commit 42c60a6 into version_3_0_0 Sep 3, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix/350 branch September 3, 2019 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants