Skip to content

Commit 2283ca6

Browse files
authored
fix(webapp): persist concurrency overrides on deploy (#2636)
* fix(webapp): display correct concurrency override base value * fix(webapp): persist concurrency overrides on deploy * fix(webapp): use correct override base value type * fix(webapp): override input is bounded by env concurrency
1 parent 8fdbbeb commit 2283ca6

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.queues/route.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DialogClose } from "@radix-ui/react-dialog";
1212
import { Form, useNavigation, useSearchParams, type MetaFunction } from "@remix-run/react";
1313
import { type ActionFunctionArgs, type LoaderFunctionArgs } from "@remix-run/server-runtime";
1414
import type { RuntimeEnvironmentType } from "@trigger.dev/database";
15+
import type { QueueItem } from "@trigger.dev/core/v3/schemas";
1516
import { useEffect, useState } from "react";
1617
import { typedjson, useTypedLoaderData } from "remix-typedjson";
1718
import { z } from "zod";
@@ -926,12 +927,7 @@ function QueueOverrideConcurrencyButton({
926927
queue,
927928
environmentConcurrencyLimit,
928929
}: {
929-
queue: {
930-
id: string;
931-
name: string;
932-
concurrencyLimit: number | null;
933-
concurrency?: { overriddenAt: Date | null };
934-
};
930+
queue: QueueItem;
935931
environmentConcurrencyLimit: number;
936932
}) {
937933
const navigation = useNavigation();
@@ -970,10 +966,10 @@ function QueueOverrideConcurrencyButton({
970966
{isOverridden ? (
971967
<Paragraph>
972968
This queue's concurrency limit is currently overridden to {currentLimit}.
973-
{queue.concurrencyLimit !== null &&
974-
` The original limit set in code was ${queue.concurrencyLimit}.`}{" "}
969+
{typeof queue.concurrency?.base === "number" &&
970+
` The original limit set in code was ${queue.concurrency.base}.`}{" "}
975971
You can update the override or remove it to restore the{" "}
976-
{queue.concurrencyLimit !== null
972+
{typeof queue.concurrency?.base === "number"
977973
? "limit set in code"
978974
: "environment concurrency limit"}
979975
.
@@ -995,6 +991,7 @@ function QueueOverrideConcurrencyButton({
995991
name="concurrencyLimit"
996992
id="concurrencyLimit"
997993
min="0"
994+
max={environmentConcurrencyLimit}
998995
value={concurrencyLimit}
999996
onChange={(e) => setConcurrencyLimit(e.target.value)}
1000997
placeholder={currentLimit.toString()}

apps/webapp/app/v3/services/createBackgroundWorker.server.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ async function createWorkerQueue(
359359
) {
360360
let queueName = sanitizeQueueName(queue.name);
361361

362-
const concurrencyLimit =
362+
const baseConcurrencyLimit =
363363
typeof queue.concurrencyLimit === "number"
364364
? Math.max(
365365
Math.min(
@@ -373,32 +373,34 @@ async function createWorkerQueue(
373373

374374
const taskQueue = await upsertWorkerQueueRecord(
375375
queueName,
376-
concurrencyLimit ?? null,
376+
baseConcurrencyLimit ?? null,
377377
orderableName,
378378
queueType,
379379
worker,
380380
prisma
381381
);
382382

383+
const newConcurrencyLimit = taskQueue.concurrencyLimit;
384+
383385
if (!taskQueue.paused) {
384-
if (typeof concurrencyLimit === "number") {
386+
if (typeof newConcurrencyLimit === "number") {
385387
logger.debug("createWorkerQueue: updating concurrency limit", {
386388
workerId: worker.id,
387389
taskQueue,
388390
orgId: environment.organizationId,
389391
projectId: environment.projectId,
390392
environmentId: environment.id,
391-
concurrencyLimit,
393+
concurrencyLimit: newConcurrencyLimit,
392394
});
393-
await updateQueueConcurrencyLimits(environment, taskQueue.name, concurrencyLimit);
395+
await updateQueueConcurrencyLimits(environment, taskQueue.name, newConcurrencyLimit);
394396
} else {
395397
logger.debug("createWorkerQueue: removing concurrency limit", {
396398
workerId: worker.id,
397399
taskQueue,
398400
orgId: environment.organizationId,
399401
projectId: environment.projectId,
400402
environmentId: environment.id,
401-
concurrencyLimit,
403+
concurrencyLimit: newConcurrencyLimit,
402404
});
403405
await removeQueueConcurrencyLimits(environment, taskQueue.name);
404406
}
@@ -455,6 +457,8 @@ async function upsertWorkerQueueRecord(
455457
},
456458
});
457459
} else {
460+
const hasOverride = taskQueue.concurrencyLimitOverriddenAt !== null;
461+
458462
taskQueue = await prisma.taskQueue.update({
459463
where: {
460464
id: taskQueue.id,
@@ -463,7 +467,9 @@ async function upsertWorkerQueueRecord(
463467
workers: { connect: { id: worker.id } },
464468
version: "V2",
465469
orderableName,
466-
concurrencyLimit,
470+
// If overridden, keep current limit and update base; otherwise update limit normally
471+
concurrencyLimit: hasOverride ? undefined : concurrencyLimit,
472+
concurrencyLimitBase: hasOverride ? concurrencyLimit : undefined,
467473
},
468474
});
469475
}

0 commit comments

Comments
 (0)