-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(nextjs): Use Vercel's waitUntil
to defer freezing of Vercel Lambdas
#12133
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
86c1332
feat(nextjs): Use Vercel's `waitUntil` to defer freezing of function
lforst 84d5c8a
.
lforst 16fe621
Merge remote-tracking branch 'origin/develop' into lforst-vercel-wait…
lforst 6ea2bad
Add comment and buffer
lforst 5102dd4
Update packages/nextjs/src/common/utils/responseEnd.ts
lforst 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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,21 @@ | ||
import { GLOBAL_OBJ } from '@sentry/utils'; | ||
|
||
interface VercelRequestContextGlobal { | ||
get?(): { | ||
waitUntil?: (task: Promise<unknown>) => void; | ||
}; | ||
} | ||
|
||
/** | ||
* Function that delays closing of a Vercel lambda until the provided promise is resolved. | ||
* | ||
* Vendored from https://www.npmjs.com/package/@vercel/functions | ||
*/ | ||
export function vercelWaitUntil(task: Promise<unknown>): void { | ||
const vercelRequestContextGlobal: VercelRequestContextGlobal | undefined = | ||
// @ts-expect-error This is not typed | ||
GLOBAL_OBJ[Symbol.for('@vercel/request-context')]; | ||
|
||
const ctx = vercelRequestContextGlobal?.get?.() ?? {}; | ||
ctx.waitUntil?.(task); | ||
} |
This file contains 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 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 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 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 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 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.
hmm, could we possibly still encapsulate this in some
flushQueue
util or so? Feels a bit "dirty" to have all thesevercelXXX
calls peppered throughout the code base, I think I'd prefer it if we could abstract this away a bit 🤔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.
tbh it feels more dirty to me to mangle Vercel API with our own intentions.
vercelWaitUntil
is basically just the vendoredwaitUntil
. Also, it's not like this is not readable or anything.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.
We literally call
vercelWaitUntil(flushSafelyWithTimeout());
every time where we are calling this, as far as I see? 😅I think it would be nicer to still just call
flushQueue
everywhere (Which can literally be:function flushQueue() { vercelWaitUntil(flushSafelyWithTimeout()); }
now), call this everywhere. if we need to adjust this logic (e.g. it does more or less or whatever) we can encapsulate this there, no need to repeat this everywhere - we call this 9 times now?But no strong feelings, if you prefer it this way all good for me :)
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.
I don't see the upside so I'll leave it as is.