-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(sdk,core,webapp,run-engine): runtime override for the combined queue concurrency limit #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
28
commits into
feat/queue-gates-contract
from
feat/queue-concurrency-overrides
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7f937e7
feat(run-engine): per-concurrency-key limit override storage and methods
matt-aitken 1b3b5a3
feat(run-engine): enforce per-key limit overrides at admit time
matt-aitken a674876
feat(database): total-override bookkeeping and per-key override table
matt-aitken b622847
feat(sdk,core,webapp): runtime overrides for total and per-key limits
matt-aitken 5a70b75
fix(run-engine,webapp,sdk): converge override failures and unpin bloc…
matt-aitken 1ace507
fix(run-engine,webapp): gate admission honors per-key overrides; hard…
matt-aitken d142d1c
fix(run-engine,webapp): flag-consistent gate overrides; generation-sa…
matt-aitken 2ea853f
fix(webapp): export queue concurrency route handlers by property access
matt-aitken 9d72d2d
refactor(sdk,core,webapp): combined concurrency override API names
matt-aitken fd07298
refactor(run-engine,webapp,sdk,database): remove per-key concurrency …
matt-aitken fd5c4b5
refactor(run-engine,webapp): drop per-key override reads and endpoints
matt-aitken 4971284
fix(run-engine): keep the ck-limits key builders while the Lua reads …
matt-aitken 3924765
fix(webapp): combined override error messages use the public name
matt-aitken 7e69dc5
feat(database): TaskQueue concurrencyVersion and role columns
matt-aitken 5ff3590
feat(sdk,core): drop the combined concurrency override client methods
matt-aitken 6785519
feat(webapp): compile task concurrency declarations at deploy
matt-aitken 437c964
fix(webapp): deploy-time guards for the limit namespace
matt-aitken 668227a
chore(webapp): the limit-name helpers are module-local
matt-aitken 12750a4
fix(webapp): validate concurrency declarations before any worker rows…
matt-aitken a14d359
fix(webapp): strict limit names at deploy and collision-proof anonymo…
matt-aitken aecfb4f
fix(webapp): queue override and reset APIs resolve queue rows only
matt-aitken f48d640
fix(webapp): trigger-time concurrency keeps the task's inline limit gate
matt-aitken ac09238
fix(webapp): deploy upserts never clobber concurrent overrides, V2 on…
matt-aitken aead915
fix(webapp): re-sync engine limits when an override lands during a de…
matt-aitken 5ec586e
fix(webapp): converge the post-deploy engine re-sync when markers kee…
matt-aitken d41e437
fix(webapp): raw gate replacement keeps the inline gate, V4 deploys v…
matt-aitken 4d347de
fix(webapp): reject gate requests that exceed the three-gate capacity
matt-aitken deef18a
fix(webapp): deploys re-assert pause, reserve limit/ in task gates, f…
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 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.
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.