-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
v4: New lifecycle hooks #1817
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
v4: New lifecycle hooks #1817
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
f59bad9
Revamping the lifecycle hooks, starting with init
ericallam 0215a8c
vibes
ericallam 2c44e59
init.ts at the root of the trigger dir is now automatically loaded
ericallam 17e1623
Improve init lifecycle hook types and fix tabler icons on spans
ericallam 1777ff4
move onStart to the new lifecycle hook system
ericallam be676fd
onFailure
ericallam 06f6a04
onStart
ericallam e816ba4
onComplete
ericallam aaf2ed8
onWait and onResume
ericallam e77e8d4
handleError
ericallam 597b7ba
adding imports
ericallam e34e520
more hooks
ericallam dc6e659
new locals API
ericallam 6001dfa
Add middleware types
ericallam 2d16d66
Add middleware hooks
ericallam 2e6d0d8
share the hook registration code
ericallam 1167889
use new onStart
ericallam b974d82
use new onFailure
ericallam 307309f
implement onComplete
ericallam 4a8d693
a couple tweaks
ericallam ef871b0
starting test executor
ericallam 2262a42
more tests and fixes
ericallam 91225da
test on failure
ericallam 87824a8
dry up some stuff
ericallam f84ddcd
test oncomplete
ericallam 6ab74c4
implement and test handleError (now catchError)
ericallam 7f804f3
middleware working and tests passing
ericallam 5edbb77
use tryCatch in TaskExecutor
ericallam 6ba2b04
more tests
ericallam d0a5c16
Add cleanup hook
ericallam 30705fd
implement cleanup
ericallam 23ae77a
handle max duration timeout errors better
ericallam ba520fc
Make sure and register all the config hooks
ericallam df9cad6
Get it all working
ericallam 3ca5985
Hooks now all use the new types, and adding some spans
ericallam 268c9f6
implement onWait/onResume
ericallam 887c5ca
Add changeset
ericallam e745fcb
Remove console.log
ericallam 1def8d0
Use allSettled so onWait/onResume errors don't break anything
ericallam 6d5d10a
Support other init file names
ericallam 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,7 @@ | ||
| --- | ||
| "@trigger.dev/sdk": patch | ||
| "trigger.dev": patch | ||
| "@trigger.dev/core": patch | ||
| --- | ||
|
|
||
| v4: New lifecycle hooks |
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 |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ export type BundleResult = { | |
| runControllerEntryPoint: string | undefined; | ||
| indexWorkerEntryPoint: string | undefined; | ||
| indexControllerEntryPoint: string | undefined; | ||
| initEntryPoint: string | undefined; | ||
| stop: (() => Promise<void>) | undefined; | ||
| }; | ||
|
|
||
|
|
@@ -229,11 +230,24 @@ export async function getBundleResultFromBuild( | |
| let runControllerEntryPoint: string | undefined; | ||
| let indexWorkerEntryPoint: string | undefined; | ||
| let indexControllerEntryPoint: string | undefined; | ||
| let initEntryPoint: string | undefined; | ||
|
|
||
| const configEntryPoint = resolvedConfig.configFile | ||
| ? relative(resolvedConfig.workingDir, resolvedConfig.configFile) | ||
| : "trigger.config.ts"; | ||
|
|
||
| // Check if the entry point is an init.ts file at the root of a trigger directory | ||
| function isInitEntryPoint(entryPoint: string): boolean { | ||
| const normalizedEntryPoint = entryPoint.replace(/\\/g, "/"); // Normalize path separators | ||
| const initFileName = "init.ts"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we support |
||
|
|
||
| // Check if it's directly in one of the trigger directories | ||
| return resolvedConfig.dirs.some((dir) => { | ||
| const normalizedDir = dir.replace(/\\/g, "/"); | ||
| return normalizedEntryPoint === `${normalizedDir}/${initFileName}`; | ||
|
ericallam marked this conversation as resolved.
Outdated
|
||
| }); | ||
| } | ||
|
|
||
| for (const [outputPath, outputMeta] of Object.entries(result.metafile.outputs)) { | ||
| if (outputPath.endsWith(".mjs")) { | ||
| const $outputPath = resolve(workingDir, outputPath); | ||
|
|
@@ -254,6 +268,8 @@ export async function getBundleResultFromBuild( | |
| indexControllerEntryPoint = $outputPath; | ||
| } else if (isIndexWorkerForTarget(outputMeta.entryPoint, target)) { | ||
| indexWorkerEntryPoint = $outputPath; | ||
| } else if (isInitEntryPoint(outputMeta.entryPoint)) { | ||
| initEntryPoint = $outputPath; | ||
| } else { | ||
| if ( | ||
| !outputMeta.entryPoint.startsWith("..") && | ||
|
|
@@ -280,6 +296,7 @@ export async function getBundleResultFromBuild( | |
| runControllerEntryPoint, | ||
| indexWorkerEntryPoint, | ||
| indexControllerEntryPoint, | ||
| initEntryPoint, | ||
| contentHash: hasher.digest("hex"), | ||
| }; | ||
| } | ||
|
|
@@ -357,6 +374,7 @@ export async function createBuildManifestFromBundle({ | |
| runControllerEntryPoint: bundle.runControllerEntryPoint ?? getRunControllerForTarget(target), | ||
| runWorkerEntryPoint: bundle.runWorkerEntryPoint ?? getRunWorkerForTarget(target), | ||
| loaderEntryPoint: bundle.loaderEntryPoint, | ||
| initEntryPoint: bundle.initEntryPoint, | ||
| configPath: bundle.configPath, | ||
| customConditions: resolvedConfig.build.conditions ?? [], | ||
| deploy: { | ||
|
|
||
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
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.
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.
@ericallam 👀