@@ -4,6 +4,7 @@ import { z } from "zod";
44import { $replica } from "~/db.server" ;
55import { requireUserId } from "~/services/session.server" ;
66import { marqs } from "~/v3/marqs/index.server" ;
7+ import { engine } from "~/v3/runEngine.server" ;
78
89const ParamSchema = z . object ( {
910 runParam : z . string ( ) ,
@@ -17,6 +18,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
1718 where : { friendlyId : runParam , project : { organization : { members : { some : { userId } } } } } ,
1819 select : {
1920 id : true ,
21+ engine : true ,
2022 friendlyId : true ,
2123 queue : true ,
2224 concurrencyKey : true ,
@@ -27,6 +29,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
2729 type : true ,
2830 slug : true ,
2931 organizationId : true ,
32+ project : true ,
33+ maximumConcurrencyLimit : true ,
3034 organization : {
3135 select : {
3236 id : true ,
@@ -41,33 +45,128 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
4145 throw new Response ( "Not Found" , { status : 404 } ) ;
4246 }
4347
44- const queueConcurrencyLimit = await marqs . getQueueConcurrencyLimit (
45- run . runtimeEnvironment ,
46- run . queue
47- ) ;
48- const envConcurrencyLimit = await marqs . getEnvConcurrencyLimit ( run . runtimeEnvironment ) ;
49- const queueCurrentConcurrency = await marqs . currentConcurrencyOfQueue (
50- run . runtimeEnvironment ,
51- run . queue ,
52- run . concurrencyKey ?? undefined
53- ) ;
54- const envCurrentConcurrency = await marqs . currentConcurrencyOfEnvironment ( run . runtimeEnvironment ) ;
55-
56- const queueReserveConcurrency = await marqs . reserveConcurrencyOfQueue (
57- run . runtimeEnvironment ,
58- run . queue ,
59- run . concurrencyKey ?? undefined
60- ) ;
61-
62- const envReserveConcurrency = await marqs . reserveConcurrencyOfEnvironment ( run . runtimeEnvironment ) ;
63-
64- return typedjson ( {
65- run,
66- queueConcurrencyLimit,
67- envConcurrencyLimit,
68- queueCurrentConcurrency,
69- envCurrentConcurrency,
70- queueReserveConcurrency,
71- envReserveConcurrency,
72- } ) ;
48+ if ( run . engine === "V1" ) {
49+ const queueConcurrencyLimit = await marqs . getQueueConcurrencyLimit (
50+ run . runtimeEnvironment ,
51+ run . queue
52+ ) ;
53+ const envConcurrencyLimit = await marqs . getEnvConcurrencyLimit ( run . runtimeEnvironment ) ;
54+ const queueCurrentConcurrency = await marqs . currentConcurrencyOfQueue (
55+ run . runtimeEnvironment ,
56+ run . queue ,
57+ run . concurrencyKey ?? undefined
58+ ) ;
59+ const envCurrentConcurrency = await marqs . currentConcurrencyOfEnvironment (
60+ run . runtimeEnvironment
61+ ) ;
62+
63+ const queueReserveConcurrency = await marqs . reserveConcurrencyOfQueue (
64+ run . runtimeEnvironment ,
65+ run . queue ,
66+ run . concurrencyKey ?? undefined
67+ ) ;
68+
69+ const envReserveConcurrency = await marqs . reserveConcurrencyOfEnvironment (
70+ run . runtimeEnvironment
71+ ) ;
72+
73+ return typedjson ( {
74+ engine : "V1" ,
75+ run,
76+ queueConcurrencyLimit,
77+ envConcurrencyLimit,
78+ queueCurrentConcurrency,
79+ envCurrentConcurrency,
80+ queueReserveConcurrency,
81+ envReserveConcurrency,
82+ keys : [ ] ,
83+ } ) ;
84+ } else {
85+ const queueConcurrencyLimit = await engine . runQueue . getQueueConcurrencyLimit (
86+ run . runtimeEnvironment ,
87+ run . queue
88+ ) ;
89+
90+ const envConcurrencyLimit = await engine . runQueue . getEnvConcurrencyLimit (
91+ run . runtimeEnvironment
92+ ) ;
93+
94+ const queueCurrentConcurrency = await engine . runQueue . currentConcurrencyOfQueue (
95+ run . runtimeEnvironment ,
96+ run . queue ,
97+ run . concurrencyKey ?? undefined
98+ ) ;
99+
100+ const envCurrentConcurrency = await engine . runQueue . currentConcurrencyOfEnvironment (
101+ run . runtimeEnvironment
102+ ) ;
103+
104+ const queueCurrentConcurrencyKey = engine . runQueue . keys . currentConcurrencyKey (
105+ run . runtimeEnvironment ,
106+ run . queue ,
107+ run . concurrencyKey ?? undefined
108+ ) ;
109+
110+ const envCurrentConcurrencyKey = engine . runQueue . keys . envCurrentConcurrencyKey (
111+ run . runtimeEnvironment
112+ ) ;
113+
114+ const queueConcurrencyLimitKey = engine . runQueue . keys . queueConcurrencyLimitKey (
115+ run . runtimeEnvironment ,
116+ run . queue
117+ ) ;
118+
119+ const envConcurrencyLimitKey = engine . runQueue . keys . envConcurrencyLimitKey (
120+ run . runtimeEnvironment
121+ ) ;
122+
123+ const releaseConcurrencyBucketKey = `engine:release-concurrency:org:${ run . runtimeEnvironment . organizationId } :proj:${ run . runtimeEnvironment . project . id } :env:${ run . runtimeEnvironment . id } :bucket` ;
124+ const releaseConcurrencyQueueKey = `engine:release-concurrency:org:${ run . runtimeEnvironment . organizationId } :proj:${ run . runtimeEnvironment . project . id } :env:${ run . runtimeEnvironment . id } :queue` ;
125+ const releaseConcurrencyMetadataKey = `engine:release-concurrency:org:${ run . runtimeEnvironment . organizationId } :proj:${ run . runtimeEnvironment . project . id } :env:${ run . runtimeEnvironment . id } :metadata` ;
126+
127+ const withPrefix = ( key : string ) => `engine:runqueue:${ key } ` ;
128+
129+ const keys = [
130+ {
131+ label : "Queue current concurrency set" ,
132+ key : withPrefix ( queueCurrentConcurrencyKey ) ,
133+ } ,
134+ {
135+ label : "Env current concurrency set" ,
136+ key : withPrefix ( envCurrentConcurrencyKey ) ,
137+ } ,
138+ {
139+ label : "Queue concurrency limit" ,
140+ key : withPrefix ( queueConcurrencyLimitKey ) ,
141+ } ,
142+ {
143+ label : "Env concurrency limit" ,
144+ key : withPrefix ( envConcurrencyLimitKey ) ,
145+ } ,
146+ {
147+ label : "Release concurrency bucket" ,
148+ key : releaseConcurrencyBucketKey ,
149+ } ,
150+ {
151+ label : "Release concurrency queue" ,
152+ key : releaseConcurrencyQueueKey ,
153+ } ,
154+ {
155+ label : "Release concurrency metadata" ,
156+ key : releaseConcurrencyMetadataKey ,
157+ } ,
158+ ] ;
159+
160+ return typedjson ( {
161+ engine : "V2" ,
162+ run,
163+ queueConcurrencyLimit,
164+ envConcurrencyLimit,
165+ queueCurrentConcurrency,
166+ envCurrentConcurrency,
167+ queueReserveConcurrency : undefined ,
168+ envReserveConcurrency : undefined ,
169+ keys,
170+ } ) ;
171+ }
73172}
0 commit comments