@@ -26,6 +26,11 @@ class TaskRunConcurrencyTracker implements MessageQueueSubscriber {
26
26
async messageEnqueued ( message : MessagePayload ) : Promise < void > { }
27
27
28
28
async messageDequeued ( message : MessagePayload ) : Promise < void > {
29
+ logger . debug ( "TaskRunConcurrencyTracker.messageDequeued()" , {
30
+ data : message . data ,
31
+ messageId : message . messageId ,
32
+ } ) ;
33
+
29
34
const data = this . getMessageData ( message ) ;
30
35
if ( ! data ) {
31
36
logger . info (
@@ -45,6 +50,11 @@ class TaskRunConcurrencyTracker implements MessageQueueSubscriber {
45
50
}
46
51
47
52
async messageAcked ( message : MessagePayload ) : Promise < void > {
53
+ logger . debug ( "TaskRunConcurrencyTracker.messageAcked()" , {
54
+ data : message . data ,
55
+ messageId : message . messageId ,
56
+ } ) ;
57
+
48
58
const data = this . getMessageData ( message ) ;
49
59
if ( ! data ) {
50
60
logger . info (
@@ -64,6 +74,11 @@ class TaskRunConcurrencyTracker implements MessageQueueSubscriber {
64
74
}
65
75
66
76
async messageNacked ( message : MessagePayload ) : Promise < void > {
77
+ logger . debug ( "TaskRunConcurrencyTracker.messageNacked()" , {
78
+ data : message . data ,
79
+ messageId : message . messageId ,
80
+ } ) ;
81
+
67
82
const data = this . getMessageData ( message ) ;
68
83
if ( ! data ) {
69
84
logger . info (
@@ -103,14 +118,18 @@ class TaskRunConcurrencyTracker implements MessageQueueSubscriber {
103
118
environmentId : string ;
104
119
deployed : boolean ;
105
120
} ) : Promise < void > {
106
- const pipeline = this . redis . pipeline ( ) ;
121
+ try {
122
+ const pipeline = this . redis . pipeline ( ) ;
107
123
108
- pipeline . sadd ( this . getTaskKey ( projectId , taskId ) , runId ) ;
109
- pipeline . sadd ( this . getTaskEnvironmentKey ( projectId , taskId , environmentId ) , runId ) ;
110
- pipeline . sadd ( this . getEnvironmentKey ( projectId , environmentId ) , runId ) ;
111
- pipeline . sadd ( this . getGlobalKey ( deployed ) , runId ) ;
124
+ pipeline . sadd ( this . getTaskKey ( projectId , taskId ) , runId ) ;
125
+ pipeline . sadd ( this . getTaskEnvironmentKey ( projectId , taskId , environmentId ) , runId ) ;
126
+ pipeline . sadd ( this . getEnvironmentKey ( projectId , environmentId ) , runId ) ;
127
+ pipeline . sadd ( this . getGlobalKey ( deployed ) , runId ) ;
112
128
113
- await pipeline . exec ( ) ;
129
+ await pipeline . exec ( ) ;
130
+ } catch ( error ) {
131
+ logger . error ( "TaskRunConcurrencyTracker.executionStarted() error" , { error } ) ;
132
+ }
114
133
}
115
134
116
135
private async executionFinished ( {
@@ -126,14 +145,18 @@ class TaskRunConcurrencyTracker implements MessageQueueSubscriber {
126
145
environmentId : string ;
127
146
deployed : boolean ;
128
147
} ) : Promise < void > {
129
- const pipeline = this . redis . pipeline ( ) ;
148
+ try {
149
+ const pipeline = this . redis . pipeline ( ) ;
130
150
131
- pipeline . srem ( this . getTaskKey ( projectId , taskId ) , runId ) ;
132
- pipeline . srem ( this . getTaskEnvironmentKey ( projectId , taskId , environmentId ) , runId ) ;
133
- pipeline . srem ( this . getEnvironmentKey ( projectId , environmentId ) , runId ) ;
134
- pipeline . srem ( this . getGlobalKey ( deployed ) , runId ) ;
151
+ pipeline . srem ( this . getTaskKey ( projectId , taskId ) , runId ) ;
152
+ pipeline . srem ( this . getTaskEnvironmentKey ( projectId , taskId , environmentId ) , runId ) ;
153
+ pipeline . srem ( this . getEnvironmentKey ( projectId , environmentId ) , runId ) ;
154
+ pipeline . srem ( this . getGlobalKey ( deployed ) , runId ) ;
135
155
136
- await pipeline . exec ( ) ;
156
+ await pipeline . exec ( ) ;
157
+ } catch ( error ) {
158
+ logger . error ( "TaskRunConcurrencyTracker.executionFinished() error" , { error } ) ;
159
+ }
137
160
}
138
161
139
162
async taskConcurrentRunCount ( projectId : string , taskId : string ) : Promise < number > {
@@ -149,21 +172,26 @@ class TaskRunConcurrencyTracker implements MessageQueueSubscriber {
149
172
}
150
173
151
174
private async getTaskCounts ( projectId : string , taskIds : string [ ] ) : Promise < number [ ] > {
152
- const pipeline = this . redis . pipeline ( ) ;
153
- taskIds . forEach ( ( taskId ) => {
154
- pipeline . scard ( this . getTaskKey ( projectId , taskId ) ) ;
155
- } ) ;
156
- const results = await pipeline . exec ( ) ;
157
- if ( ! results ) {
175
+ try {
176
+ const pipeline = this . redis . pipeline ( ) ;
177
+ taskIds . forEach ( ( taskId ) => {
178
+ pipeline . scard ( this . getTaskKey ( projectId , taskId ) ) ;
179
+ } ) ;
180
+ const results = await pipeline . exec ( ) ;
181
+ if ( ! results ) {
182
+ return [ ] ;
183
+ }
184
+ return results . map ( ( [ err , count ] ) => {
185
+ if ( err ) {
186
+ console . error ( "Error in getTaskCounts:" , err ) ;
187
+ return 0 ;
188
+ }
189
+ return count as number ;
190
+ } ) ;
191
+ } catch ( error ) {
192
+ logger . error ( "TaskRunConcurrencyTracker.getTaskCounts() error" , { error } ) ;
158
193
return [ ] ;
159
194
}
160
- return results . map ( ( [ err , count ] ) => {
161
- if ( err ) {
162
- console . error ( "Error in getTaskCounts:" , err ) ;
163
- return 0 ;
164
- }
165
- return count as number ;
166
- } ) ;
167
195
}
168
196
169
197
async projectTotalConcurrentRunCount ( projectId : string , taskIds : string [ ] ) : Promise < number > {
@@ -177,7 +205,7 @@ class TaskRunConcurrencyTracker implements MessageQueueSubscriber {
177
205
) : Promise < Record < string , number > > {
178
206
const counts = await this . getTaskCounts ( projectId , taskIds ) ;
179
207
return taskIds . reduce ( ( acc , taskId , index ) => {
180
- acc [ taskId ] = counts [ index ] ;
208
+ acc [ taskId ] = counts [ index ] ?? 0 ;
181
209
return acc ;
182
210
} , { } as Record < string , number > ) ;
183
211
}
@@ -186,23 +214,28 @@ class TaskRunConcurrencyTracker implements MessageQueueSubscriber {
186
214
projectId : string ,
187
215
environmentIds : string [ ]
188
216
) : Promise < Record < string , number > > {
189
- const pipeline = this . redis . pipeline ( ) ;
190
- environmentIds . forEach ( ( environmentId ) => {
191
- pipeline . scard ( this . getEnvironmentKey ( projectId , environmentId ) ) ;
192
- } ) ;
193
- const results = await pipeline . exec ( ) ;
194
- if ( ! results ) {
195
- return Object . fromEntries ( environmentIds . map ( ( id ) => [ id , 0 ] ) ) ;
196
- }
217
+ try {
218
+ const pipeline = this . redis . pipeline ( ) ;
219
+ environmentIds . forEach ( ( environmentId ) => {
220
+ pipeline . scard ( this . getEnvironmentKey ( projectId , environmentId ) ) ;
221
+ } ) ;
222
+ const results = await pipeline . exec ( ) ;
223
+ if ( ! results ) {
224
+ return Object . fromEntries ( environmentIds . map ( ( id ) => [ id , 0 ] ) ) ;
225
+ }
197
226
198
- return results . reduce ( ( acc , [ err , count ] , index ) => {
199
- if ( err ) {
200
- console . error ( "Error in environmentConcurrentRunCounts:" , err ) ;
227
+ return results . reduce ( ( acc , [ err , count ] , index ) => {
228
+ if ( err ) {
229
+ console . error ( "Error in environmentConcurrentRunCounts:" , err ) ;
230
+ return acc ;
231
+ }
232
+ acc [ environmentIds [ index ] ] = count as number ;
201
233
return acc ;
202
- }
203
- acc [ environmentIds [ index ] ] = count as number ;
204
- return acc ;
205
- } , { } as Record < string , number > ) ;
234
+ } , { } as Record < string , number > ) ;
235
+ } catch ( error ) {
236
+ logger . error ( "TaskRunConcurrencyTracker.environmentConcurrentRunCounts() error" , { error } ) ;
237
+ return Object . fromEntries ( environmentIds . map ( ( id ) => [ id , 0 ] ) ) ;
238
+ }
206
239
}
207
240
208
241
private getTaskKey ( projectId : string , taskId : string ) : string {
@@ -231,6 +264,11 @@ function getTracker() {
231
264
) ;
232
265
}
233
266
267
+ logger . debug ( "Initializing TaskRunConcurrencyTracker" , {
268
+ redisHost : env . REDIS_HOST ,
269
+ redisPort : env . REDIS_PORT ,
270
+ } ) ;
271
+
234
272
return new TaskRunConcurrencyTracker ( {
235
273
redis : {
236
274
keyPrefix : "concurrencytracker:" ,
0 commit comments