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

Feature: adding the --ignore-group CLI option #784

Closed

Conversation

ovidiul
Copy link
Contributor

@ovidiul ovidiul commented Oct 27, 2021

This PR fixes #736.

As suggested in the issue, a --ignore-group option is the desired approach to name this.

The PR also adds support for multiple comma-separated groups, so --ignore-group=group1,group2 could be used as well. This implementation would also allow for the --group option to take comma-separated values as --group=group1,group2.

Why this approach?

Looking at the $runner->setup( $batch, $hooks, $group, $force, $ignore_group ); alternative, where we would have to pass the $ignore_group additional parameter, the $group and $ignore_group are very similar, so maybe using a flag to specify which group to ignore as proposed in this PR might make the code a little bit simpler?

Tests - TBD

Happy to add any related tests if this approach is considered valid.

@ovidiul ovidiul changed the title Feature: adding the --exclude-group CLI option Feature: adding the --ignore-group CLI option Oct 27, 2021
@ovidiul ovidiul marked this pull request as ready for review October 28, 2021 07:33
@barryhughes barryhughes changed the base branch from master to trunk March 9, 2022 00:16
@barryhughes
Copy link
Member

Sorry for the delay, here.

  • This looks like a valuable and useful change.
  • Some very minor tweaks (formatting etc) to make.
  • It seems making the ignore prefix even more 'obscure' would be an easy way to add just a little more safety.
  • Let's also document the change (ie, in the docs/ folder).

We are a little pressed for bandwidth right now, so can't act on the above immediately, but this looks good in general. Thank you!

Copy link
Member

@barryhughes barryhughes left a comment

Choose a reason for hiding this comment

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

Leaving some notes for when we pick this up at some future point ✍🏽

classes/abstracts/ActionScheduler_Store.php Outdated Show resolved Hide resolved
classes/abstracts/ActionScheduler_Store.php Outdated Show resolved Hide resolved
classes/abstracts/ActionScheduler_Store.php Outdated Show resolved Hide resolved
Comment on lines 239 to 243
// removing the ignored group prefix from slug if present.
$slug = preg_replace( '/(' . preg_quote( self::IGNORE_GROUP_FLAG, null ) . ')?(.*)/m', '$2', $slug );

// further sanitisation here with `sanitize_title` maybe?
return $slug;
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should also anchor ^the regex? Re sanitization; I wonder if esc_sql would (also) make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the ^ regex change as well as the esc_sql filtering

classes/data-stores/ActionScheduler_DBStore.php Outdated Show resolved Hide resolved
classes/data-stores/ActionScheduler_DBStore.php Outdated Show resolved Hide resolved
$params[] = $group_id;
if ( count( $include_group_ids ) ) {
$where .= ' AND group_id IN (%s)';
$params[] = implode( ',', $include_group_ids );
Copy link
Member

@barryhughes barryhughes Nov 23, 2022

Choose a reason for hiding this comment

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

Asking this without actually testing 😅 ... but, won't the group ID arrays at this point be comma separated strings without quotation? That is, we will get:

( foo, bar, baz )

Instead of:

( 'foo', 'bar', 'baz' )

If so, we should add quoting at some suitable point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The $include_group_ids will actually contain the numerical ID's of each group found in the DB, taken from above line

$group_id             = $this->get_group_id( $sanitized_group_name, false );

so I don't think we need to add any quotes here...

@ovidiul
Copy link
Contributor Author

ovidiul commented Nov 24, 2022

Thanks for the suggestions @barryhughes , I've addressed the mentioned issues. 👍

@@ -29,7 +29,8 @@ These are the commands available to use with Action Scheduler:
* `--batch-size` - This is the number of actions to run in a single batch. The default is `100`.
* `--batches` - This is the number of batches to run. Using 0 means that batches will continue running until there are no more actions to run.
* `--hooks` - Process only actions with specific hook or hooks, like `'woocommerce_scheduled_subscription_payment'`. By default, actions with any hook will be processed. Define multiple hooks as a comma separated string (without spaces), e.g. `--hooks=woocommerce_scheduled_subscription_trial_end,woocommerce_scheduled_subscription_payment,woocommerce_scheduled_subscription_expiration`
* `--group` - Process only actions in a specific group, like `'woocommerce-memberships'`. By default, actions in any group (or no group) will be processed.
* `--group` - Process only actions in a specific group, like `'woocommerce-memberships'`. By default, actions in any group (or no group) will be processed. Accepts comma-separated list of groups to filter by. Adding --*IGNORE*-- in front of a group will cause it to be ignored.
* `--ignore-group` - Ignore processing actions from groups found inside the comma separated list of values.
Copy link
Member

Choose a reason for hiding this comment

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

Nice, thank you 👍

@rrennick
Copy link
Contributor

rrennick commented Feb 6, 2023

@ovidiul Thanks for writing this. It's a great feature to add. I wrote #905 as a base for adding more granular queue runner control starting with excluding a group. It would great if we had your feedback on the PR.

This was referenced Feb 22, 2023
@barryhughes
Copy link
Member

Thanks for all the work here, and for pioneering a way forward! Closing, since most of the proposed functionality has been introduced via #905 and #918.

I want to also note that one thing those PRs do not add support for is processing multiple groups in a single queue runner, which there may still be value in.

@barryhughes barryhughes closed this Mar 8, 2023
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.

Option to ignore some groups when using the wp-cli command
3 participants