Repository navigation
Answer a bounded part of a cron sequence too - #42
Open
KalimeroMK wants to merge 4 commits into
Open
KalimeroMK wants to merge 4 commits into
KalimeroMK wants to merge 4 commits into
Conversation
`CronExpressionTrigger` now implements `TriggerRangeInterface`. The library walks the expression itself, so a batch costs its own length rather than the span it is taken from: a month of backlog opens as cheaply as an hour of it. Asked for the first run at or after a date, it has to be asked twice. An expression names a minute, and the library answers with the start of that minute when told the current date counts, so half a minute past a run it answers with the run just missed, which is behind the date asked about. The guard against that is taken from #12, where the same question is asked the same way. The timezone the expression is read in was worked out in `getNextRunDate()` and is now shared, because a range has to be read in the same one: not the timezone of the date asked about, which for a date restored from a checkpoint is UTC whatever it was saved in.
A trigger that implements TriggerInterface alone is asked one date at a time, whatever the size of the backlog. That was the behaviour before a range existed and it is unchanged, but it was nowhere written down, and a reader of the new interface has no way to tell whether implementing it is expected of them.
The periodic trigger answered a date half an hour into a run with the run it had just missed, at every change of the clock. The cron trigger is asked the same question a different way, so the same sweep is run against it: three zones that move the clock by half an hour and by a whole one, four days on which they move it, every hour of each.
Reviewer's GuideThis PR adds efficient bounded-sequence support to Sequence diagram for cron bounded batch retrievalsequenceDiagram
participant Caller
participant CronExpressionTrigger
participant CronLibrary
Caller->>CronExpressionTrigger: getRunDates(after, before, limit, phase)
CronExpressionTrigger->>CronLibrary: getMultipleRunDates(limit, cursor, false, false, timezone)
loop Up to limit
CronLibrary-->>CronExpressionTrigger: next cron date
alt date >= before
CronExpressionTrigger-->>Caller: bounded dates
else date < before
CronExpressionTrigger->>CronExpressionTrigger: append date
end
end
CronExpressionTrigger-->>Caller: bounded dates
Sequence diagram for cron next-run boundary handlingsequenceDiagram
participant Caller
participant CronExpressionTrigger
participant CronLibrary
Caller->>CronExpressionTrigger: getNextRunDateAtOrAfter(date, phase)
alt phase >= date
CronExpressionTrigger->>CronExpressionTrigger: getNextRunDate(phase)
CronExpressionTrigger-->>Caller: next run after phase
else no usable phase
CronExpressionTrigger->>CronLibrary: getNextRunDate(date, 0, true, timezone)
CronLibrary-->>CronExpressionTrigger: candidate minute
alt candidate < date
CronExpressionTrigger->>CronExpressionTrigger: getNextRunDate(date)
CronExpressionTrigger-->>Caller: next run after date
else candidate >= date
CronExpressionTrigger-->>Caller: candidate
end
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/Trigger/CronExpressionTrigger.php" line_range="100" />
<code_context>
+
+ // The library walks the expression itself, so the cost is the batch and not the span it
+ // is taken from: a backlog of a month is as cheap to open as a backlog of an hour.
+ foreach ($this->cron->getMultipleRunDates($limit, $cursor, false, false, $this->timezone()) as $date) {
+ $date = DateTimeImmutable::createFromInterface($date);
+
</code_context>
<issue_to_address>
**Cron batches contain incorrect dates**
When a caller requests a cron range with a non-default expression timezone or a matching run at the start, `getMultipleRunDates()` receives the timezone in the wrong positional slot, so the library does not evaluate the range with the requested timezone; batches contain shifted, repeated, or otherwise unintended dates.
Pass the timezone in the library’s timezone argument position.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: src/Trigger/CronExpressionTrigger.php:100
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Based on #41, which adds the interface this implements.
What does this PR do?
CronExpressionTriggeranswers the two range questions as well. The library walks the expression itself, so a batch costs its own length rather than the span it is taken from: a month of backlog opens as cheaply as an hour of it.Asked for the first run at or after a date, it has to be asked twice. An expression names a minute, and the library answers with the start of that minute when told the current date counts, so half a minute past a run it answers with the run just missed, which is behind the date asked about. The guard against that is taken from #12, where the same question is asked the same way.
The timezone the expression is read in was worked out inside
getNextRunDate()and is now shared by all three methods, because a range has to be read in the same one: not the timezone of the date asked about, which for a date restored from a checkpoint is UTC whatever it was saved in.What it is held to
The same property as #41: a range holds exactly the dates the trigger gives one at a time. The provider covers every hour,
0 2 * * *in Skopje across the spring change — the day 02:00 does not exist and the library answers 03:00 — and 29 February over nine years.The clock-change sweep that caught the defect in #41's first commit is run against this trigger too, over three zones that move the clock by half an hour and by a whole one, four days on which they move it, every hour of each: no answer is ever before the date asked about.
What is left for #34
The generator's use of a range. By this ticket's own Related work, #34 owns the checkpoint and replay decisions, and
TaskGenerator::getTasks()is rewritten by #17 and #19 besides.A trigger implementing
TriggerInterfacealone is asked one date at a time, as before. That was the behaviour already; it is now written down, in the interface and in the README.Summary by Sourcery
Add efficient bounded cron-sequence queries while preserving the existing one-run trigger behavior and sequence semantics.
New Features:
CronExpressionTriggerto return bounded batches of cron runs and the first run at or after a date, including support for continuation phases.Bug Fixes:
Enhancements:
Documentation:
Tests:
Chores: