-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(sdk,core,webapp,run-engine): runtime overrides for queue total concurrency limits #4829
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
matt-aitken
wants to merge
30
commits into
feat/queue-gates-contract
from
feat/queue-concurrency-overrides
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
fa0a0b3
feat(run-engine): per-concurrency-key limit override storage and methods
matt-aitken 43b478d
feat(run-engine): enforce per-key limit overrides at admit time
matt-aitken a3cdd3b
feat(database): total-override bookkeeping and per-key override table
matt-aitken eeb3e44
feat(sdk,core,webapp): runtime overrides for total and per-key limits
matt-aitken 7927d1d
fix(run-engine,webapp,sdk): converge override failures and unpin bloc…
matt-aitken a3c8c6a
fix(run-engine,webapp): gate admission honors per-key overrides; hard…
matt-aitken 7b2f366
fix(run-engine,webapp): flag-consistent gate overrides; generation-sa…
matt-aitken 0e29d90
fix(webapp): export queue concurrency route handlers by property access
matt-aitken 109540f
refactor(sdk,core,webapp): combined concurrency override API names
matt-aitken c7927de
refactor(run-engine,webapp,sdk,database): remove per-key concurrency …
matt-aitken 119a962
refactor(run-engine,webapp): drop per-key override reads and endpoints
matt-aitken 84a9619
fix(run-engine): keep the ck-limits key builders while the Lua reads …
matt-aitken f69ba93
fix(webapp): combined override error messages use the public name
matt-aitken 2a38daa
feat(database): TaskQueue concurrencyVersion and role columns
matt-aitken 905d688
feat(sdk,core): drop the combined concurrency override client methods
matt-aitken 6c3b417
feat(webapp): compile task concurrency declarations at deploy
matt-aitken e314856
fix(webapp): deploy-time guards for the limit namespace
matt-aitken 61b32fb
chore(webapp): the limit-name helpers are module-local
matt-aitken 550985c
fix(webapp): validate concurrency declarations before any worker rows…
matt-aitken 056b4f3
fix(webapp): strict limit names at deploy and collision-proof anonymo…
matt-aitken 87ee30a
fix(webapp): queue override and reset APIs resolve queue rows only
matt-aitken 1a43646
fix(webapp): trigger-time concurrency keeps the task's inline limit gate
matt-aitken 8336d5c
fix(webapp): deploy upserts never clobber concurrent overrides, V2 on…
matt-aitken 010742b
fix(webapp): re-sync engine limits when an override lands during a de…
matt-aitken 5722cfe
fix(webapp): converge the post-deploy engine re-sync when markers kee…
matt-aitken 6eb28d4
fix(webapp): raw gate replacement keeps the inline gate, V4 deploys v…
matt-aitken 979b99c
fix(webapp): reject gate requests that exceed the three-gate capacity
matt-aitken 2b2a798
fix(webapp): deploys re-assert pause, reserve limit/ in task gates, f…
matt-aitken bcee429
fix(webapp): resume syncs the fresh row's limit and honors a zero limit
matt-aitken 235e628
chore: drop the combined concurrency changeset, the surface never ships
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
98 changes: 98 additions & 0 deletions
98
apps/webapp/app/routes/api.v1.queues.$queueParam.concurrency.combined.override.ts
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,98 @@ | ||
| import { json } from "@remix-run/server-runtime"; | ||
| import { type RetrieveQueueParam, RetrieveQueueType } from "@trigger.dev/core/v3"; | ||
| import { z } from "zod"; | ||
| import { toQueueItem } from "~/presenters/v3/QueueRetrievePresenter.server"; | ||
| import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server"; | ||
| import { concurrencySystem } from "~/v3/services/concurrencySystemInstance.server"; | ||
|
|
||
| const BodySchema = z.object({ | ||
| type: RetrieveQueueType.default("id"), | ||
| concurrencyLimit: z.number().int().min(0).max(100000), | ||
| }); | ||
|
|
||
| const route = createActionApiRoute( | ||
| { | ||
| body: BodySchema, | ||
| params: z.object({ | ||
| queueParam: z.string().transform((val) => val.replace(/%2F/g, "/")), | ||
| }), | ||
| authorization: { | ||
| action: "write", | ||
| resource: () => ({ type: "queues" }), | ||
| }, | ||
| }, | ||
|
matt-aitken marked this conversation as resolved.
|
||
| async ({ params, body, authentication }) => { | ||
| const input: RetrieveQueueParam = | ||
| body.type === "id" | ||
| ? params.queueParam | ||
| : { | ||
| type: body.type, | ||
| name: decodeURIComponent(params.queueParam).replace(/%2F/g, "/"), | ||
| }; | ||
|
|
||
| return concurrencySystem.queues | ||
| .overrideTotalConcurrencyLimit(authentication.environment, input, body.concurrencyLimit) | ||
| .match( | ||
| (queue) => { | ||
| return json( | ||
| toQueueItem({ | ||
| friendlyId: queue.friendlyId, | ||
| name: queue.name, | ||
| type: queue.type, | ||
| running: queue.running, | ||
| queued: queue.queued, | ||
| concurrencyLimit: queue.concurrencyLimit, | ||
| concurrencyLimitBase: queue.concurrencyLimitBase, | ||
| concurrencyLimitOverriddenAt: queue.concurrencyLimitOverriddenAt, | ||
| concurrencyLimitOverriddenBy: null, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| paused: queue.paused, | ||
| }), | ||
| { status: 200 } | ||
| ); | ||
| }, | ||
| (error) => { | ||
| switch (error.type) { | ||
| case "queue_not_found": { | ||
| return json({ error: "Queue not found" }, { status: 404 }); | ||
| } | ||
| case "invalid_override": | ||
| case "concurrency_limit_exceeds_maximum": { | ||
| return json({ error: error.message }, { status: 400 }); | ||
| } | ||
| case "queue_update_failed": { | ||
| return json( | ||
| { error: "Failed to update queue total concurrency limit" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| case "sync_queue_concurrency_to_engine_failed": { | ||
| return json({ error: "Failed to sync the total concurrency limit" }, { status: 500 }); | ||
| } | ||
| case "get_queue_stats_failed": { | ||
| return json({ error: "Failed to read queue stats" }, { status: 500 }); | ||
| } | ||
| case "other": { | ||
| return json( | ||
| { error: "Failed to update queue total concurrency limit" }, | ||
| { | ||
| status: 500, | ||
| } | ||
| ); | ||
| } | ||
| default: { | ||
| return json( | ||
| { error: "Failed to update queue total concurrency limit" }, | ||
| { | ||
| status: 500, | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| export const action = route.action; | ||
| /** The builder's loader answers non-POST methods with a 405. */ | ||
| export const loader = route.loader; | ||
99 changes: 99 additions & 0 deletions
99
apps/webapp/app/routes/api.v1.queues.$queueParam.concurrency.combined.reset.ts
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,99 @@ | ||
| import { json } from "@remix-run/server-runtime"; | ||
| import { type RetrieveQueueParam, RetrieveQueueType } from "@trigger.dev/core/v3"; | ||
| import { z } from "zod"; | ||
| import { toQueueItem } from "~/presenters/v3/QueueRetrievePresenter.server"; | ||
| import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server"; | ||
| import { concurrencySystem } from "~/v3/services/concurrencySystemInstance.server"; | ||
|
|
||
| const BodySchema = z.object({ | ||
| type: RetrieveQueueType.default("id"), | ||
| }); | ||
|
|
||
| const route = createActionApiRoute( | ||
| { | ||
| body: BodySchema, | ||
| params: z.object({ | ||
| queueParam: z.string().transform((val) => val.replace(/%2F/g, "/")), | ||
| }), | ||
| authorization: { | ||
| action: "write", | ||
| resource: () => ({ type: "queues" }), | ||
| }, | ||
| }, | ||
| async ({ params, body, authentication }) => { | ||
| const input: RetrieveQueueParam = | ||
| body.type === "id" | ||
| ? params.queueParam | ||
| : { | ||
| type: body.type, | ||
| name: decodeURIComponent(params.queueParam).replace(/%2F/g, "/"), | ||
| }; | ||
|
|
||
| return concurrencySystem.queues | ||
| .resetTotalConcurrencyLimit(authentication.environment, input) | ||
| .match( | ||
| (queue) => { | ||
| return json( | ||
| toQueueItem({ | ||
| friendlyId: queue.friendlyId, | ||
| name: queue.name, | ||
| type: queue.type, | ||
| running: queue.running, | ||
| queued: queue.queued, | ||
| concurrencyLimit: queue.concurrencyLimit, | ||
| concurrencyLimitBase: queue.concurrencyLimitBase, | ||
| concurrencyLimitOverriddenAt: queue.concurrencyLimitOverriddenAt, | ||
| concurrencyLimitOverriddenBy: null, | ||
| paused: queue.paused, | ||
| }), | ||
| { status: 200 } | ||
| ); | ||
| }, | ||
| (error) => { | ||
| switch (error.type) { | ||
| case "queue_not_found": { | ||
| return json({ error: "Queue not found" }, { status: 404 }); | ||
| } | ||
| case "queue_not_overridden": { | ||
| return json( | ||
| { error: "The queue total concurrency limit is not overridden" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
| case "queue_update_failed": { | ||
| return json( | ||
| { error: "Failed to reset the queue total concurrency limit" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| case "sync_queue_concurrency_to_engine_failed": { | ||
| return json({ error: "Failed to sync the total concurrency limit" }, { status: 500 }); | ||
| } | ||
| case "get_queue_stats_failed": { | ||
| return json({ error: "Failed to read queue stats" }, { status: 500 }); | ||
| } | ||
| case "other": { | ||
| return json( | ||
| { error: "Failed to reset the queue total concurrency limit" }, | ||
| { | ||
| status: 500, | ||
| } | ||
| ); | ||
| } | ||
| default: { | ||
| return json( | ||
| { error: "Failed to reset the queue total concurrency limit" }, | ||
| { | ||
| status: 500, | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| export const action = route.action; | ||
| /** The builder's loader answers non-POST methods with a 405. */ | ||
| export const loader = route.loader; |
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.