Skip to content

Conversation

@josedumas
Copy link
Contributor

@josedumas josedumas commented Dec 10, 2022

This PR is to resolve the enhancement so that wp_get_ready_cron_jobs() is used.

I have decided to add a control flag and not refactor two methods for not adding extra code, although it may be formally better to apply 2 different methods.

I have come across the problem that the get_cron_events method returns an error if the $crons array is empty, and this can happen just with wp_get_ready_cron_jobs. Therefore, in order to pass the functional tests, I have added the one that checks that the array is empty only when we are not in the "--due-now" situation.

I have performed the functional tests and they are correct. But I understand that it may be a bad practice to add a control flag. I have justified above the reason for the decision.

Another alternative that I have ruled out is to simply call the pre_get_ready_cron_jobs filter inside the get_cron_events method. This solution would have the advantage of not adding this flag, but we would still have the hidden problem that the result of the filter could return an empty array and therefore would not pass the functional tests (although in my tests it does). I will upload it in another branch in my repository (with_apply_filter)

Fixes #86

@josedumas josedumas requested a review from a team as a code owner December 10, 2022 10:57
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Couple of small nits but looks good to me overall. Thanks for sticking with this!

@josedumas
Copy link
Contributor Author

I have made the changes with your suggestions and it looks much better. I upload new PR with that changes !

@josedumas josedumas closed this Dec 13, 2022
@wojsmol
Copy link
Contributor

wojsmol commented Dec 13, 2022

@josedumas Please reopen this PR.

@josedumas josedumas reopened this Dec 13, 2022
@danielbachhuber danielbachhuber changed the title When --due-now use wp_get_ready_cron_jobs Use wp_get_ready_cron_jobs() for --due-now to apply core filter Dec 13, 2022
@danielbachhuber danielbachhuber added this to the 2.2.0 milestone Dec 13, 2022
@danielbachhuber danielbachhuber self-requested a review December 13, 2022 14:33
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Great work on this, @josedumas !

@danielbachhuber danielbachhuber merged commit 6b4385c into wp-cli:main Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apply pre_get_ready_cron_jobs filter to crons when --due-now is provided

3 participants