-
Notifications
You must be signed in to change notification settings - Fork 119
Only release claims on pending actions. #1248
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
base: trunk
Are you sure you want to change the base?
Conversation
What I'm not sure is the potential backward compatibility conflicts here. I don't know why existing extensions would need completed actions to get reset back to claim_id 0, but we can't be sure that is the case. |
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.
Actions on my end still appear to be reset to 0
. Here's what I did:
- Ran
wp generate_actions
which created a lot ofas_performance_testing_action
actions - Manually run the actions by visiting Tools->Actoin Schedule
- Run the above SQL query and see actions are set to
0
after completion.

Are there any other steps I need to take or that I did wrong?
@joshuatf , sorry, I made an assumption that the site wouldn't have any existing actions that were already failed or completed that were reset to claim_id 0. I've updated the instructions. Can you confirm whether those were new actions or not? |
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.
Hey @prettyboymp, sorry for the late review. This is happening on new actions, though it doesn't seem related to the area you touched.
The code you've added otherwise LGTM; I'm just not entirely sure where claims are being released in my case.
It might be good to get someone else more familiar with AS to take a glance at this and give final approval, especially around any potential backwards compatibility issues. cc @jorgeatorres
*/ | ||
$action_ids = $wpdb->get_col( $wpdb->prepare( "SELECT action_id FROM {$wpdb->actionscheduler_actions} WHERE claim_id = %d", $claim->get_id() ) ); | ||
$action_ids = $wpdb->get_col( $wpdb->prepare( "SELECT action_id FROM {$wpdb->actionscheduler_actions} WHERE claim_id = %d AND status = %s", $claim->get_id(), self::STATUS_PENDING ) ); |
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.
I can confirm that this array is empty and the below query to set the claim_id = 0
does not get run. However, my claims in the DB are still getting set to 0
.
Is there anywhere else this might be happening or is it possible for multiple instances of AS to be running at once?
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.
Note that actions processed via Tools > Scheduled Actions are not claimed/released. Is this how you're running the actions @joshuatf?
For the runner to properly stake a claim and then release the actions, you'd have to either let those actions run naturally or use a runner such as the CLI one (i.e. run wp action-scheduler run
).
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.
This looks good to me @prettyboymp and tests well. I like the performance improvements this can bring and also that by retaining the claim ID we've gained a bit on the auditing side, which is always useful.
I'm not too concerned about the backwards compatibility of this change in the sense that 3rd parties need completed actions to have claim_id = 0
. In theory they shouldn't necessarily be querying the database directly.
That said, we do have a claimed
field that can be used to query actions via as_get_scheduled_actions()
(implemented as query_actions()
in the data stores). We would be changing the behavior here as claimed = true
wouldn't have returned completed actions prior to this change. Maybe we can "force" the query function to ignore non-pending actions when the claimed = true
arg is provided.
FWIW, this arg is used in a few places, and it'd be good to check that we're not breaking anything in those places. In particular, the queue cleaner seems fine, but other integrations such as the one with WC's SSR might need some adjustments.
What do you think?
…us::get_action_status_date() as it doesn't necessarily make sense to filter out claimed actions.
…tatus_date() as it doesn't necessarily make sense to filter out claimed actions.
@jorgeatorres, I updated the status reports to no longer include the
I’m a bit hesitant to introduce forced manipulation of the I also reviewed all plugins on WooCommerce.com and didn’t find any instances where |
Fixes: #1105, improves #1104
The current query for claiming actions can get really slow for a sites that process a ton of actions. Part of the cause to this is that all actions are reset back to claim_id
0
after a batch is processed. This increases the amount of time needed to query the pending actions that need to be claimed because the initial segment of the index used to claim actions is heavily seeded with0
values causing the optimizer to frequently choose a less performant index.This improves that by no longer resetting the claim_id of completed or running actions back to
0
when a claim is released. Since onlypending
actions are still processed, leaving these with their old shouldn't cause any side-effects, and if anything improves debugging potential issues since the original claim that processed any actions will still be present.Testing Instructions:
claim_id=0
or take note of the current count to verify the results of the changes later:mu-plugins
file and a wp-cli commandwp generate_actions
to create a bunch of pseudo actions to be processed.SELECT count(*) from wp_actionscheduler_actions where claim_id = 0 and status != 'pending'
.Note that these changes will not effect actions that have already been completed or failed as those really no longer matter to the system and are only retained for a period of time for admin review. They will eventually get cleaned up via a job.