Repository navigation
Preview a schedule's next runs, and keep the calendar jump from skipping one - #365
Merged
Merged
Conversation
GET /api/automations/preview?cron=<five fields>&timezone=<IANA> answers
{next_runs: [three ISO UTC times]} by the rule the scheduler fires by
(repo.ts nextRunAt, then cron.ts nextOccurrence), so an editor can show
what a schedule will do while a person types it, without computing run
times of its own. The first run is this minute when it is an occurrence,
as the tick would still fire a schedule enabled now. The zone defaults to
UTC as a create's does; a cron that names no date gets no runs; a cron or
zone the scheduler cannot read, or a cron longer than any a person types
(512 characters), answers 400 with the service's plain error ("cron must be
a valid 5-field expression", "timezone must be a valid IANA name"). The
/api/schedules alias answers the same, and the route and fields match the
hosted product's.
nextOccurrence passes a run of days the cron rules out by calendar arithmetic and resumes at noon on the day before the next date it names. Across a change of half a day or more, or a clock set back past midnight, that jump could skip a real occurrence: from 2011-12-01, "0 0 31 12 *" in Pacific/Apia answered 2012 instead of 2011-12-30T10:00Z (Apia crossed the date line), and "* 23 4 3 *" in Antarctica/Casey skipped the 23:00 its 2010 change brought back. It now jumps only where a day-by-day walk would see the same dates: not while one of the two dates before the current one matches, and only when it lands on the day before the named date. Otherwise the walk takes the next day as before. The Apia, Kiritimati, Kwajalein and Casey changes give the walk's answers again, and a comparison with the walk over every zone, twelve date-restricted crons and starts from 1970 to 2035 (58,740 searches) found no difference; a cron that names no date still costs a fraction of a millisecond.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Two follow-ups to #363, backend only.
Preview a schedule before it is saved.
GET /api/automations/preview?cron=<five fields>&timezone=<IANA>(also under/api/schedules) answers{ "next_runs": [three ISO UTC times] }. It uses the rule the scheduler fires by:repo.tsnextRunAtfor the first run, thencron.tsnextOccurrence. An editor can call it, debounced, while a person types a schedule, and show what it will do without computing run times of its own.UTC, as a create's does.400with a plain error:cron must be a valid 5-field expressionortimezone must be a valid IANA name.Keep the calendar jump from skipping an occurrence. #363 made
nextOccurrencepass the days a cron rules out using calendar arithmetic, resuming at noon on the day before the next date it names. Across a change of half a day or more, or a clock set back past midnight, that jump could skip a real occurrence:0 0 31 12 *inPacific/Apiafrom 2011-12-01 answered 2012 instead of 2011-12-30T10:00Z (Apia crossed the date line).* 23 4 3 *inAntarctica/Caseyskipped the 23:00 that its 2010 change brought back.It now jumps only where a day-by-day walk would see the same dates. It does not jump while one of the two dates before the current one matches, and it jumps only when it lands on the day before the named date. A comparison with the walk over every zone, twelve date-restricted crons and starts from 1970 to 2035 (58,740 searches) found no difference. A cron that names no date still costs a fraction of a millisecond.
The release-window trigger from 0114 stays. Dropping it in a later migration would break a still-serving older backend whenever an upgrade applies 0114 and that migration in one batch, and this repository cannot know when every deployment has passed 0114.
Known limit: like
next_due_at, the preview names an occurrence the scheduler is due to fire. If a person enables a schedule at 09:00:10 after the minute's tick already ran at 09:00:05, the 09:00 run waits for the next day.Tests: the preview route (aliases, UTC default, no-date crons, plain errors, the length cap), the current-minute start, and the Apia, Kiritimati, Kwajalein and Casey changes. The full backend suite passes (3544 + 119).
Need help on this PR? Tag
@codesmith-botwith what you need.