-
Notifications
You must be signed in to change notification settings - Fork 117
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
Fix recurring schedules, e.g. Cron and Interval schedules #333
Conversation
8c0e2cc
to
8fdc9f2
Compare
I've rebased this on |
@thenbrent This is looking good. Just a couple things: Related to #331, we should start ensuring any new code merged has consistent spacing. The WP coding standards for spacing provide for good readability. I used the following to find some of the inconsistent spacing (in added code only)
I'm getting a warning in WP CLI and in the debug log:
|
c8c93de
to
3fb9454
Compare
@rrennick good call. I've fixed up spacing and rebased in the fixes. I ran
I can't see any remaining calls to |
Yes. Other than a rebase this is good to go. |
Recurring schedules issues, as outlined in #330. This patch fixes recurring schedules, and in the process, refactors all schedules to avoid duplicate code and ambiguity of properties and parameters. This patch introduces to important new base classes: * ActionScheduler_Abstract_Schedule and * ActionScheduler_Abstract_RecurringSchedule These are then used to implement all other schedule types - cron, recurring/interval and simple. This helps unify the data on each schedule. For example, schedules used to have different property names referring to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp was the same as ActionScheduler_SimpleSchedule::timestamp. Both of these timestamps actually referring to the date the action was scheduled, but due to ambiguity in naming, like 'start' or 'date' or 'first', the data was sometimes used to refer to the scheduled date, and sometimes the first instance of a recurring schedule. While unifying the properties, their nomenclature has also been changed to avoid ambiguity. Fixes #330 and associated issues - #256, #258, #291, #293 and #296.
Preserve prior behaviour where first run date is the next matching Cron date by calculating this in the factory method. Also make it more clear this is the behaviour of the $first / $timestamp param, by renaming them and improving php docblock. Also add a new unit test to ensure successive instances of cron actions are scheduled correcting aftering being run /processed.
By making sure that the $start date is used if it matches the cron expression, rather than forcing a date after $start.
Now that the scheduled date and future / next date calculations have been separated, we can create a new schedule which will still return a cancelled action's scheduled date, but never show a cancelled action as having a next date. Previously, cancelled actions used the Null schedule, which would always return NULL for both the next scheduled date, and the scheduled date of the action, meaning we could never find out when a cancelled action was originally scheduled to run.
Improvements: 1. test 3 instances not just 2, just in case 2. test both run() and process_action() methods 3. rename to disambiguate from the new test for cron actions
Instead of duplicating the same logic.
Rebased, thanks @rrennick! |
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.
LGTM
Prior to #333, reccuring schedules used different property names to refer to equivalent data. For example, IntervalSchedule::start_timestamp was the same as SimpleSchedule::timestamp. PR #333 aligned properties and property names for better inheritance. To guard against the possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to also store the data with the old property names so if it's unserialized in AS < 3.0, the schedule doesn't end up with a 0 recurrance, which creates an infinite loop. Fixes #340.
Prior to #333, recurring schedules used different property names to refer to equivalent data. For example, IntervalSchedule::start_timestamp was the same as SimpleSchedule::timestamp. PR #333 aligned properties and property names for better inheritance. To guard against the possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to also store the data with the old property names so if it's unserialized in AS < 3.0, the schedule doesn't end up with a 0 recurrence. Fixes #340.
Prior to #333, recurring schedules used different property names to refer to equivalent data. For example, IntervalSchedule::start_timestamp was the same as SimpleSchedule::timestamp. PR #333 aligned properties and property names for better inheritance. To guard against the possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to also store the data with the old property names so if it's unserialized in AS < 3.0, the schedule doesn't end up with a 0 recurrence. Fixes #340.
This is a monster, late stage PR for 3.0.0. However, because there are breaking changes, and it resolves a number of discrepancies and gotchas in the recurring and cron actions & schedules, I think it's worth including in 3.0.0 instead of waiting for a 4.0.0, or shipping in a 3.x.x version.
Fixes #330 and associated issues - #256, #258, #291, #293 and #296.
As outlined in #330, there are a number of issues with recurring action that use either a Cron or Interval schedule.
This PR fixes recurring schedules, and in the process, refactors all schedules to avoid duplicate code and ambiguity of properties and parameters.
This patch introduces two important new base classes:
ActionScheduler_Abstract_Schedule
andActionScheduler_Abstract_RecurringSchedule
These are then used to implement all other schedule types - cron, recurring/interval and simple. This helps unify the data on each schedule. For example, schedules used to have different property names referring to equivalent data like
ActionScheduler_IntervalSchedule::start_timestamp
andActionScheduler_SimpleSchedule::timestamp
.Both of these timestamps actually referring to the date the action was scheduled, but due to ambiguity in naming, like "start" or "date" or "first", the data was sometimes used to refer to the scheduled date, and sometimes the first instance of a recurring schedule. While unifying the properties, their nomenclature has also been changed to avoid ambiguity.
While working on this, I also took the opportunity to:
ActionScheduler_CanceledSchedule
class which takes advantage of the separation of scheduled / next dates on a schedule so that a cancelled action's scheduled date can be derived (and displayed in the admin)