-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(server): New TTL system, enforce max queue length limits, lazy waitpoint creation #2980
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
base: main
Are you sure you want to change the base?
Changes from all commits
b9b0664
60717a4
6369faf
965721c
21dae6f
814a9a4
998d93c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||
| import { Ratelimit } from "@upstash/ratelimit"; | ||||||||||||||||||||||||||||||||
| import { RuntimeEnvironmentType } from "@trigger.dev/database"; | ||||||||||||||||||||||||||||||||
| import { createHash } from "node:crypto"; | ||||||||||||||||||||||||||||||||
| import { env } from "~/env.server"; | ||||||||||||||||||||||||||||||||
| import { getCurrentPlan } from "~/services/platform.v3.server"; | ||||||||||||||||||||||||||||||||
|
|
@@ -12,6 +13,8 @@ import { BasePresenter } from "./basePresenter.server"; | |||||||||||||||||||||||||||||||
| import { singleton } from "~/utils/singleton"; | ||||||||||||||||||||||||||||||||
| import { logger } from "~/services/logger.server"; | ||||||||||||||||||||||||||||||||
| import { CheckScheduleService } from "~/v3/services/checkSchedule.server"; | ||||||||||||||||||||||||||||||||
| import { engine } from "~/v3/runEngine.server"; | ||||||||||||||||||||||||||||||||
| import { getQueueSizeLimit, getQueueSizeLimitSource } from "~/v3/utils/queueLimits.server"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Create a singleton Redis client for rate limit queries | ||||||||||||||||||||||||||||||||
| const rateLimitRedisClient = singleton("rateLimitQueryRedisClient", () => | ||||||||||||||||||||||||||||||||
|
|
@@ -66,8 +69,7 @@ export type LimitsResult = { | |||||||||||||||||||||||||||||||
| logRetentionDays: QuotaInfo | null; | ||||||||||||||||||||||||||||||||
| realtimeConnections: QuotaInfo | null; | ||||||||||||||||||||||||||||||||
| batchProcessingConcurrency: QuotaInfo; | ||||||||||||||||||||||||||||||||
| devQueueSize: QuotaInfo; | ||||||||||||||||||||||||||||||||
| deployedQueueSize: QuotaInfo; | ||||||||||||||||||||||||||||||||
| queueSize: QuotaInfo; | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| features: { | ||||||||||||||||||||||||||||||||
| hasStagingEnvironment: FeatureInfo; | ||||||||||||||||||||||||||||||||
|
|
@@ -84,11 +86,13 @@ export class LimitsPresenter extends BasePresenter { | |||||||||||||||||||||||||||||||
| organizationId, | ||||||||||||||||||||||||||||||||
| projectId, | ||||||||||||||||||||||||||||||||
| environmentId, | ||||||||||||||||||||||||||||||||
| environmentType, | ||||||||||||||||||||||||||||||||
| environmentApiKey, | ||||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||||
| organizationId: string; | ||||||||||||||||||||||||||||||||
| projectId: string; | ||||||||||||||||||||||||||||||||
| environmentId: string; | ||||||||||||||||||||||||||||||||
| environmentType: RuntimeEnvironmentType; | ||||||||||||||||||||||||||||||||
| environmentApiKey: string; | ||||||||||||||||||||||||||||||||
| }): Promise<LimitsResult> { | ||||||||||||||||||||||||||||||||
| // Get organization with all limit-related fields | ||||||||||||||||||||||||||||||||
|
|
@@ -167,6 +171,30 @@ export class LimitsPresenter extends BasePresenter { | |||||||||||||||||||||||||||||||
| batchRateLimitConfig | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Get current queue size for this environment | ||||||||||||||||||||||||||||||||
| // We need the runtime environment fields for the engine query | ||||||||||||||||||||||||||||||||
| const runtimeEnv = await this._replica.runtimeEnvironment.findFirst({ | ||||||||||||||||||||||||||||||||
| where: { id: environmentId }, | ||||||||||||||||||||||||||||||||
| select: { | ||||||||||||||||||||||||||||||||
| id: true, | ||||||||||||||||||||||||||||||||
| maximumConcurrencyLimit: true, | ||||||||||||||||||||||||||||||||
| concurrencyLimitBurstFactor: true, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| let currentQueueSize = 0; | ||||||||||||||||||||||||||||||||
| if (runtimeEnv) { | ||||||||||||||||||||||||||||||||
| const engineEnv = { | ||||||||||||||||||||||||||||||||
| id: runtimeEnv.id, | ||||||||||||||||||||||||||||||||
| type: environmentType, | ||||||||||||||||||||||||||||||||
| maximumConcurrencyLimit: runtimeEnv.maximumConcurrencyLimit, | ||||||||||||||||||||||||||||||||
| concurrencyLimitBurstFactor: runtimeEnv.concurrencyLimitBurstFactor, | ||||||||||||||||||||||||||||||||
| organization: { id: organizationId }, | ||||||||||||||||||||||||||||||||
| project: { id: projectId }, | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| currentQueueSize = (await engine.lengthOfEnvQueue(engineEnv)) ?? 0; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
ericallam marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Get plan-level limits | ||||||||||||||||||||||||||||||||
| const schedulesLimit = limits?.schedules?.number ?? null; | ||||||||||||||||||||||||||||||||
| const teamMembersLimit = limits?.teamMembers?.number ?? null; | ||||||||||||||||||||||||||||||||
|
|
@@ -282,19 +310,12 @@ export class LimitsPresenter extends BasePresenter { | |||||||||||||||||||||||||||||||
| canExceed: true, | ||||||||||||||||||||||||||||||||
| isUpgradable: true, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| devQueueSize: { | ||||||||||||||||||||||||||||||||
| name: "Dev queue size", | ||||||||||||||||||||||||||||||||
| description: "Maximum pending runs in development environments", | ||||||||||||||||||||||||||||||||
| limit: organization.maximumDevQueueSize ?? null, | ||||||||||||||||||||||||||||||||
| currentUsage: 0, // Would need to query Redis for this | ||||||||||||||||||||||||||||||||
| source: organization.maximumDevQueueSize ? "override" : "default", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| deployedQueueSize: { | ||||||||||||||||||||||||||||||||
| name: "Deployed queue size", | ||||||||||||||||||||||||||||||||
| description: "Maximum pending runs in deployed environments", | ||||||||||||||||||||||||||||||||
| limit: organization.maximumDeployedQueueSize ?? null, | ||||||||||||||||||||||||||||||||
| currentUsage: 0, // Would need to query Redis for this | ||||||||||||||||||||||||||||||||
| source: organization.maximumDeployedQueueSize ? "override" : "default", | ||||||||||||||||||||||||||||||||
| queueSize: { | ||||||||||||||||||||||||||||||||
| name: "Max queued runs", | ||||||||||||||||||||||||||||||||
| description: "Maximum pending runs per individual queue in this environment", | ||||||||||||||||||||||||||||||||
| limit: getQueueSizeLimit(environmentType, organization), | ||||||||||||||||||||||||||||||||
| currentUsage: currentQueueSize, | ||||||||||||||||||||||||||||||||
| source: getQueueSizeLimitSource(environmentType, organization), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
|
Comment on lines
313
to
319
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Queue-size quota never shows an upgrade action.
💡 Suggested change queueSize: {
name: "Max queued runs",
description: "Maximum pending runs across all queues in this environment",
limit: getQueueSizeLimit(environmentType, organization),
currentUsage: currentQueueSize,
source: getQueueSizeLimitSource(environmentType, organization),
+ isUpgradable: true,
},📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| features: { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,7 +345,7 @@ export default function Page() { | |
| <BigNumber | ||
| title="Queued" | ||
| value={environment.queued} | ||
| suffix={env.paused && environment.queued > 0 ? "paused" : undefined} | ||
| suffix={env.paused ? <span className="text-warning">paused</span> : undefined} | ||
| animate | ||
| accessory={ | ||
| <div className="flex items-start gap-1"> | ||
|
|
@@ -364,7 +364,7 @@ export default function Page() { | |
| /> | ||
| </div> | ||
| } | ||
| valueClassName={cn(env.paused ? "text-warning" : undefined, "tabular-nums")} | ||
| valueClassName={env.paused ? "text-warning tabular-nums" : "tabular-nums"} | ||
| compactThreshold={1000000} | ||
| /> | ||
| <BigNumber | ||
|
|
@@ -509,7 +509,10 @@ export default function Page() { | |
| {queues.length > 0 ? ( | ||
| queues.map((queue) => { | ||
| const limit = queue.concurrencyLimit ?? environment.concurrencyLimit; | ||
| const isAtLimit = queue.running >= limit; | ||
| const isAtConcurrencyLimit = queue.running >= limit; | ||
| const isAtQueueLimit = | ||
| environment.queueSizeLimit !== null && | ||
| queue.queued >= environment.queueSizeLimit; | ||
|
Comment on lines
+512
to
+515
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: rg -n "queueSizeLimit" --type=ts --type=tsx -C 3Repository: triggerdotdev/trigger.dev Length of output: 96 🏁 Script executed: rg -n "queueSizeLimit" -C 3Repository: triggerdotdev/trigger.dev Length of output: 6310 🏁 Script executed: rg -n "function getQueueSizeLimit|const getQueueSizeLimit|export.*getQueueSizeLimit" -C 5Repository: triggerdotdev/trigger.dev Length of output: 2121 🏁 Script executed: cat -n apps/webapp/app/v3/utils/queueLimits.server.tsRepository: triggerdotdev/trigger.dev Length of output: 2183 🏁 Script executed: rg -n "guardQueueSizeLimitsForEnv" -C 10Repository: triggerdotdev/trigger.dev Length of output: 10225 🏁 Script executed: cat -n apps/webapp/app/v3/queueSizeLimits.server.tsRepository: triggerdotdev/trigger.dev Length of output: 1577 🏁 Script executed: sed -n '340,375p' apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.queues/route.tsxRepository: triggerdotdev/trigger.dev Length of output: 177 🏁 Script executed: find apps/webapp/app/routes -name "route.tsx" | grep queuesRepository: triggerdotdev/trigger.dev Length of output: 173 🏁 Script executed: sed -n '340,375p' 'apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.queues/route.tsx'Repository: triggerdotdev/trigger.dev Length of output: 1559 🏁 Script executed: sed -n '510,525p' 'apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.queues/route.tsx'Repository: triggerdotdev/trigger.dev Length of output: 901 The per-queue queue limit badge uses incorrect semantics.
This comparison will almost never trigger correctly. For example, with a 1000-item environment limit and 10 queues, a single queue would need 1000 items to trigger the badge, even though the environment might already be at capacity with items spread across queues. Use 🤖 Prompt for AI Agents |
||
| const queueFilterableName = `${queue.type === "task" ? "task/" : ""}${ | ||
| queue.name | ||
| }`; | ||
|
|
@@ -535,7 +538,12 @@ export default function Page() { | |
| Paused | ||
| </Badge> | ||
| ) : null} | ||
| {isAtLimit ? ( | ||
| {isAtQueueLimit ? ( | ||
| <Badge variant="extra-small" className="text-error"> | ||
| At queue limit | ||
| </Badge> | ||
| ) : null} | ||
| {isAtConcurrencyLimit ? ( | ||
| <Badge variant="extra-small" className="text-warning"> | ||
| At concurrency limit | ||
| </Badge> | ||
|
|
@@ -546,7 +554,8 @@ export default function Page() { | |
| alignment="right" | ||
| className={cn( | ||
| "w-[1%] pl-16 tabular-nums", | ||
| queue.paused ? "opacity-50" : undefined | ||
| queue.paused ? "opacity-50" : undefined, | ||
| isAtQueueLimit && "text-error" | ||
| )} | ||
| > | ||
| {queue.queued} | ||
|
|
@@ -557,7 +566,7 @@ export default function Page() { | |
| "w-[1%] pl-16 tabular-nums", | ||
| queue.paused ? "opacity-50" : undefined, | ||
| queue.running > 0 && "text-text-bright", | ||
| isAtLimit && "text-warning" | ||
| isAtConcurrencyLimit && "text-warning" | ||
| )} | ||
| > | ||
| {queue.running} | ||
|
|
@@ -577,7 +586,7 @@ export default function Page() { | |
| className={cn( | ||
| "w-[1%] pl-16", | ||
| queue.paused ? "opacity-50" : undefined, | ||
| isAtLimit && "text-warning", | ||
| isAtConcurrencyLimit && "text-warning", | ||
| queue.concurrency?.overriddenAt && "font-medium text-text-bright" | ||
| )} | ||
| > | ||
|
|
||
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.
Defaulting
MAXIMUM_DEV_QUEUE_SIZEchanges enforcement behavior.This turns previously-unlimited dev environments into a hard 500-queue cap (via
guardQueueSizeLimitsForEnv). If that’s not intentional, remove the default and require an explicit env var to enable the limit.💡 Suggested change (avoid unintended hard limit)
📝 Committable suggestion
🤖 Prompt for AI Agents