-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: implement cron window spread backend #4566
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3ce772a
update db schema
carderne 9147888
failing fastpath test
carderne 6ee08e7
add schedule timing logic
carderne ec1ec2e
cron window persistence
carderne 07fd09e
disable fastpath for delayed jobs
carderne f92cb8d
persist schedule phase
carderne 923db55
thread effective schedule through schedule-engine
carderne f003d9c
add feature flag
carderne 951f899
add timestamp to clickhouse
carderne d91193c
more o11y
carderne 3131ed5
support zero, improve tests, add server-change
carderne c499599
add non-null check constraint
carderne f6fd57b
Update schedule-windows.md
carderne 73b1a69
cap at 24h, no d option, cap too-large windows and log
carderne e38b457
prevent multiple schedules after downtime
carderne bca75ca
preserve existing jobs when schedule unchanged
carderne 00c1ddd
fix upcoming timestamps
carderne bc4e47f
simplify phase_source span
carderne 40059cb
add spread_fraction rollout
carderne 6d46620
fix: restore timing fields to declarative schedule sync select
carderne 062dd0b
persist phase to db when active
carderne 28d307a
format
carderne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: feature | ||
| --- | ||
|
|
||
| Add backend support for delaying cron schedules within a specified window with a minimum of 60 seconds. |
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { parseScheduleWindow } from "@internal/schedule-engine"; | ||
| import type { ScheduleWindow } from "@trigger.dev/core/v3"; | ||
|
|
||
| const SECONDS_PER_UNIT = { | ||
| m: 60, | ||
| h: 3_600, | ||
| } as const; | ||
|
|
||
| export type ScheduleWindowDatabaseFields = { | ||
| windowDurationSeconds: number | null; | ||
| windowPercentage: number | null; | ||
| }; | ||
|
|
||
| export function normalizeScheduleWindow( | ||
| window: ScheduleWindow | undefined | ||
| ): ScheduleWindowDatabaseFields { | ||
| if (window === undefined) { | ||
| return { | ||
| windowDurationSeconds: null, | ||
| windowPercentage: null, | ||
| }; | ||
| } | ||
|
|
||
| const parsedWindow = parseScheduleWindow(window); | ||
|
|
||
| if (parsedWindow.type === "percentage") { | ||
| return { | ||
| windowDurationSeconds: null, | ||
| windowPercentage: parsedWindow.percentage, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| windowDurationSeconds: parsedWindow.durationSeconds, | ||
| windowPercentage: null, | ||
| }; | ||
| } | ||
|
|
||
| export function formatScheduleWindow({ | ||
| windowDurationSeconds, | ||
| windowPercentage, | ||
| }: ScheduleWindowDatabaseFields): ScheduleWindow | undefined { | ||
| if (windowPercentage !== null) { | ||
| return `${windowPercentage}%`; | ||
| } | ||
|
|
||
| if (windowDurationSeconds === null) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (windowDurationSeconds === 0) { | ||
| return "0m"; | ||
| } | ||
|
|
||
| if (windowDurationSeconds % SECONDS_PER_UNIT.h === 0) { | ||
| return `${windowDurationSeconds / SECONDS_PER_UNIT.h}h`; | ||
| } | ||
|
|
||
| return `${windowDurationSeconds / SECONDS_PER_UNIT.m}m`; | ||
| } | ||
|
|
||
| export function validateScheduleWindowSyntax( | ||
| window: ScheduleWindow | undefined | ||
| ): { valid: true } | { valid: false; message: string } { | ||
| if (window === undefined) { | ||
| return { valid: true }; | ||
| } | ||
|
|
||
| try { | ||
| parseScheduleWindow(window); | ||
| return { valid: true }; | ||
| } catch (error) { | ||
| return { | ||
| valid: false, | ||
| message: error instanceof Error ? error.message : String(error), | ||
| }; | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.