-
-
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
Open
+1,968
−89
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c090e06
update db schema
carderne b6f7254
failing fastpath test
carderne 8005f93
add schedule timing logic
carderne 7171362
cron window persistence
carderne 2f5ac02
disable fastpath for delayed jobs
carderne ed9f165
persist schedule phase
carderne 78f6764
thread effective schedule through schedule-engine
carderne 52ac1e1
add feature flag
carderne 22577c2
add timestamp to clickhouse
carderne 91d52f1
more o11y
carderne 686efad
support zero, improve tests, add server-change
carderne bd99602
add non-null check constraint
carderne 75a11b4
Update schedule-windows.md
carderne beb6074
cap at 24h, no d option, cap too-large windows and log
carderne 0044bbf
prevent multiple schedules after downtime
carderne 466cfcd
preserve existing jobs when schedule unchanged
carderne d78ed00
fix upcoming timestamps
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.
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.