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 CLI exclude-group filter #905

Merged
merged 2 commits into from
Feb 16, 2023
Merged

add CLI exclude-group filter #905

merged 2 commits into from
Feb 16, 2023

Conversation

rrennick
Copy link
Contributor

@rrennick rrennick commented Feb 6, 2023

Closes #736

This PR is an alternative to #784. #784 is a great solution if adding group exclusion were the only filter we were looking to add to the queue runners. However, we are considering adding:

  • hook exclusion
  • priorities
  • retries
  • settings screen for managing the async and cron runners

#784 works around the limitation that we cannot modify the claim_actions function definition by embedding flags in existing parameters. While that works for one flag/parameter it isn't practical for adding several. This PR avoid that by adding a new function to the base tables DB store.

It also lays the groundwork for adding additional filters. For example, excluding hooks will only require a few additional lines of code. Secondly, all added filters could be implemented on the async and cron runners through a settings screen without using similar parameter tampering.

Testing

  • Disable the default runners.
  • I used this hook to create test actions:
add_action( 'init', function() {
    $groups = [
      'automatewoo',
      'woocommerce',
      'woocommerce-admin',
      'internal',
    ];
    $hooks = [
      'alpha',
      'beta',
      'gamma',
      'delta',
    ];
    $group = rand( 0, 3 );
    $hook = rand( 0, 3 );
    $unique = rand( 1, 9 );

    as_schedule_single_action(
        time() + MINUTE_IN_SECONDS,
        'init_' . $hooks[ $hook ] . $unique,
        [],
        'test-' . $groups[ $group ]
    );
}, 99 );
  • Allow some time for actions to be created
  • Then ran the following a few minutes apart
wp action-scheduler run --group=alpha
// check that all pending past due alpha actions ran
wp action-scheduler run --exclude-group=beta
// check that beta is the only group with pending past due actions

Changelog

Add - Add support for excluding group(s) when using the WP CLI queue runner.

@rrennick rrennick requested review from a team and Konamiman and removed request for a team February 6, 2023 19:47
@Konamiman
Copy link
Contributor

By looking at the implementation it seems that when both --group and --exclude-group are specified, only --group is taken in account. That's fine (I guess combining both is out of scope for this pr) but maybe it's something that should be explicitly stated in the help.

@rrennick
Copy link
Contributor Author

@Konamiman Thanks for the suggestion. I've added that to the option description.

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