-
-
Notifications
You must be signed in to change notification settings - Fork 999
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
61d999f
37e4dbe
058b5db
aaea8d6
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: { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
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