-
-
Notifications
You must be signed in to change notification settings - Fork 801
v4: simplified release concurrency system and status changes #2284
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
15 commits
Select commit
Hold shift + click to select a range
d5e7f6b
WIP
ericallam 949f404
Make release concurrency system extremely simple, everything just rel…
ericallam f507be3
update the deadlock detection to use the new lockedQueueReleaseConcur…
ericallam 018baa7
WIP new release concurrency system
ericallam e75319c
Remove releaseConcurrency and releaseConcurrencyOnWaitpoint
ericallam 287d09a
Added new DEQUEUED status
ericallam dfc88e5
Introduce the new "current dequeued concurrency set"
ericallam f5f12cb
Remove QUEUED_EXECUTING because we no longer "eagerly" release before…
ericallam ffc494c
Remove waitpoint test for QUEUED_EXECUTING
ericallam 3615d65
Add isWaiting
ericallam 74f32a4
Add changeset
ericallam 54db95d
Use createdAt for ordering realtime runs instead of number
ericallam e73626d
Clarify the envCurrentDequeuedKey usage
ericallam 256f6e3
mock the db.server file to fix the tests
ericallam c16d8e8
Updated changset "EXECUTED" -> "EXECUTING"
matt-aitken 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,45 @@ | ||
--- | ||
"@trigger.dev/sdk": patch | ||
--- | ||
|
||
Removes the `releaseConcurrencyOnWaitpoint` option on queues and the `releaseConcurrency` option on various wait functions. Replaced with the following default behavior: | ||
|
||
- Concurrency is never released when a run is first blocked via a waitpoint, at either the env or queue level. | ||
- Concurrency is always released when a run is checkpointed and shutdown, at both the env and queue level. | ||
|
||
Additionally, environment concurrency limits now have a new "Burst Factor", defaulting to 2.0x. The "Burst Factor" allows the environment-wide concurrency limit to be higher than any individual queue's concurrency limit. For example, if you have an environment concurrency limit of 100, and a Burst Factor of 2.0x, then you can execute up to 200 runs concurrently, but any one task/queue can still only execute 100 runs concurrently. | ||
|
||
We've done some work cleaning up the run statuses. The new statuses are: | ||
|
||
- `PENDING_VERSION`: Task is waiting for a version update because it cannot execute without additional information (task, queue, etc.) | ||
- `QUEUED`: Task is waiting to be executed by a worker | ||
- `DEQUEUED`: Task has been dequeued and is being sent to a worker to start executing. | ||
- `EXECUTING`: Task is currently being executed by a worker | ||
- `WAITING`: Task has been paused by the system, and will be resumed by the system | ||
- `COMPLETED`: Task has been completed successfully | ||
- `CANCELED`: Task has been canceled by the user | ||
- `FAILED`: Task has failed to complete, due to an error in the system | ||
- `CRASHED`: Task has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage | ||
- `SYSTEM_FAILURE`: Task has failed to complete, due to an error in the system | ||
- `DELAYED`: Task has been scheduled to run at a specific time | ||
- `EXPIRED`: Task has expired and won't be executed | ||
- `TIMED_OUT`: Task has reached it's maxDuration and has been stopped | ||
|
||
We've removed the following statuses: | ||
|
||
- `WAITING_FOR_DEPLOY`: This is no longer used, and is replaced by `PENDING_VERSION` | ||
- `FROZEN`: This is no longer used, and is replaced by `WAITING` | ||
- `INTERRUPTED`: This is no longer used | ||
- `REATTEMPTING`: This is no longer used, and is replaced by `EXECUTING` | ||
|
||
We've also added "boolean" helpers to runs returned via the API and from Realtime: | ||
|
||
- `isQueued`: Returns true when the status is `QUEUED`, `PENDING_VERSION`, or `DELAYED` | ||
- `isExecuting`: Returns true when the status is `EXECUTING`, `DEQUEUED`. These count against your concurrency limits. | ||
- `isWaiting`: Returns true when the status is `WAITING`. These do not count against your concurrency limits. | ||
- `isCompleted`: Returns true when the status is any of the completed statuses. | ||
- `isCanceled`: Returns true when the status is `CANCELED` | ||
- `isFailed`: Returns true when the status is any of the failed statuses. | ||
- `isSuccess`: Returns true when the status is `COMPLETED` | ||
|
||
This change adds the ability to easily detect which runs are being counted against your concurrency limit by filtering for both `EXECUTING` or `DEQUEUED`. |
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,57 @@ | ||
import { | ||
API_VERSION_HEADER_NAME, | ||
API_VERSION as CORE_API_VERSION, | ||
} from "@trigger.dev/core/v3/serverOnly"; | ||
import { z } from "zod"; | ||
|
||
export const CURRENT_API_VERSION = CORE_API_VERSION; | ||
|
||
export const NON_SPECIFIC_API_VERSION = "none"; | ||
|
||
export type API_VERSIONS = typeof CURRENT_API_VERSION | typeof NON_SPECIFIC_API_VERSION; | ||
|
||
export function getApiVersion(request: Request): API_VERSIONS { | ||
const apiVersion = request.headers.get(API_VERSION_HEADER_NAME); | ||
|
||
if (apiVersion === CURRENT_API_VERSION) { | ||
return apiVersion; | ||
} | ||
|
||
return NON_SPECIFIC_API_VERSION; | ||
} | ||
|
||
// This has been copied from the core package to allow us to use these types in the webapp | ||
export const RunStatusUnspecifiedApiVersion = z.enum([ | ||
/// Task is waiting for a version update because it cannot execute without additional information (task, queue, etc.). Replaces WAITING_FOR_DEPLOY | ||
"PENDING_VERSION", | ||
/// Task hasn't been deployed yet but is waiting to be executed | ||
"WAITING_FOR_DEPLOY", | ||
/// Task is waiting to be executed by a worker | ||
"QUEUED", | ||
/// Task is currently being executed by a worker | ||
"EXECUTING", | ||
/// Task has failed and is waiting to be retried | ||
"REATTEMPTING", | ||
/// Task has been paused by the system, and will be resumed by the system | ||
"FROZEN", | ||
/// Task has been completed successfully | ||
"COMPLETED", | ||
/// Task has been canceled by the user | ||
"CANCELED", | ||
/// Task has been completed with errors | ||
"FAILED", | ||
/// Task has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage | ||
"CRASHED", | ||
/// Task was interrupted during execution, mostly this happens in development environments | ||
"INTERRUPTED", | ||
/// Task has failed to complete, due to an error in the system | ||
"SYSTEM_FAILURE", | ||
/// Task has been scheduled to run at a specific time | ||
"DELAYED", | ||
/// Task has expired and won't be executed | ||
"EXPIRED", | ||
/// Task has reached it's maxDuration and has been stopped | ||
"TIMED_OUT", | ||
]); | ||
|
||
export type RunStatusUnspecifiedApiVersion = z.infer<typeof RunStatusUnspecifiedApiVersion>; |
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
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.
@nicktrn we'll need to document this for the self-hosting guides/charts. We can recommend setting this to
2.0