Defensive checks in cron rescheduling #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
This PR includes a code refactoring of the TaskManager section and additional checks to unsure that the Task class is being instanced if its managed the cron is scheduled.
In addition the custom schedules are included from a new
TaskManagerSchedules
class that handles them.There was a lot of repetitive code that was abstracted and put in an
AbstractTaskManager
class that then is extended by all the other tasks manager classes.Initially this PR was meant to solve issues related to cron that were randomly displaying in the log, such as:
Cron unschedule event error for hook: nfd_module_installer_plugin_deactivation_event, Error code: could_not_set, Error message: The cron event list could not be saved., Data: {"schedule":false,"args":[]}
This kind of issue present when a cron is executed multiple and simultaneous times, so that trigger an error with the cron option update. This is an issue that affect WordPress since 6.1 version. (in the last section i'm attaching the related WP Core thread)
For this PR we are including the refactoring and additional checks and cron clearing after their completion as is the best we can do for the moment. We can evaluate further investigation for the future.
Type of Change
Production
Development
Video
Checklist
Further comments
Here the thread related to the WordPress Cron issue: