@@ -12,6 +12,7 @@ import { BasePresenter } from "./basePresenter.server";
1212import { singleton } from "~/utils/singleton" ;
1313import { logger } from "~/services/logger.server" ;
1414import { CheckScheduleService } from "~/v3/services/checkSchedule.server" ;
15+ import { engine } from "~/v3/runEngine.server" ;
1516
1617// Create a singleton Redis client for rate limit queries
1718const rateLimitRedisClient = singleton ( "rateLimitQueryRedisClient" , ( ) =>
@@ -66,8 +67,7 @@ export type LimitsResult = {
6667 logRetentionDays : QuotaInfo | null ;
6768 realtimeConnections : QuotaInfo | null ;
6869 batchProcessingConcurrency : QuotaInfo ;
69- devQueueSize : QuotaInfo ;
70- deployedQueueSize : QuotaInfo ;
70+ queueSize : QuotaInfo ;
7171 } ;
7272 features : {
7373 hasStagingEnvironment : FeatureInfo ;
@@ -167,6 +167,32 @@ export class LimitsPresenter extends BasePresenter {
167167 batchRateLimitConfig
168168 ) ;
169169
170+ // Get current queue size for this environment
171+ const runtimeEnv = await this . _replica . runtimeEnvironment . findFirst ( {
172+ where : { id : environmentId } ,
173+ select : {
174+ id : true ,
175+ type : true ,
176+ organizationId : true ,
177+ projectId : true ,
178+ maximumConcurrencyLimit : true ,
179+ concurrencyLimitBurstFactor : true ,
180+ } ,
181+ } ) ;
182+
183+ let currentQueueSize = 0 ;
184+ if ( runtimeEnv ) {
185+ const engineEnv = {
186+ id : runtimeEnv . id ,
187+ type : runtimeEnv . type ,
188+ maximumConcurrencyLimit : runtimeEnv . maximumConcurrencyLimit ,
189+ concurrencyLimitBurstFactor : runtimeEnv . concurrencyLimitBurstFactor ,
190+ organization : { id : runtimeEnv . organizationId } ,
191+ project : { id : runtimeEnv . projectId } ,
192+ } ;
193+ currentQueueSize = ( await engine . lengthOfEnvQueue ( engineEnv ) ) ?? 0 ;
194+ }
195+
170196 // Get plan-level limits
171197 const schedulesLimit = limits ?. schedules ?. number ?? null ;
172198 const teamMembersLimit = limits ?. teamMembers ?. number ?? null ;
@@ -282,19 +308,24 @@ export class LimitsPresenter extends BasePresenter {
282308 canExceed : true ,
283309 isUpgradable : true ,
284310 } ,
285- devQueueSize : {
286- name : "Dev queue size" ,
287- description : "Maximum pending runs in development environments" ,
288- limit : organization . maximumDevQueueSize ?? null ,
289- currentUsage : 0 , // Would need to query Redis for this
290- source : organization . maximumDevQueueSize ? "override" : "default" ,
291- } ,
292- deployedQueueSize : {
293- name : "Deployed queue size" ,
294- description : "Maximum pending runs in deployed environments" ,
295- limit : organization . maximumDeployedQueueSize ?? null ,
296- currentUsage : 0 , // Would need to query Redis for this
297- source : organization . maximumDeployedQueueSize ? "override" : "default" ,
311+ queueSize : {
312+ name : "Max queue size" ,
313+ description : "Maximum pending runs in this environment" ,
314+ limit :
315+ runtimeEnv ?. type === "DEVELOPMENT"
316+ ? ( organization . maximumDevQueueSize ?? env . MAXIMUM_DEV_QUEUE_SIZE ?? null )
317+ : ( organization . maximumDeployedQueueSize ?? env . MAXIMUM_DEPLOYED_QUEUE_SIZE ?? null ) ,
318+ currentUsage : currentQueueSize ,
319+ // "plan" = org has a value (typically set by billing sync)
320+ // "default" = no org value, using env var fallback
321+ source :
322+ runtimeEnv ?. type === "DEVELOPMENT"
323+ ? organization . maximumDevQueueSize
324+ ? "plan"
325+ : "default"
326+ : organization . maximumDeployedQueueSize
327+ ? "plan"
328+ : "default" ,
298329 } ,
299330 } ,
300331 features : {
0 commit comments