@@ -20,6 +20,7 @@ const QUEUE_NAME = 'connectionSyncQueue';
20
20
21
21
type JobPayload = {
22
22
connectionId : number ,
23
+ connectionName : string ,
23
24
orgId : number ,
24
25
config : ConnectionConfig ,
25
26
} ;
@@ -60,12 +61,13 @@ export class ConnectionManager implements IConnectionManager {
60
61
61
62
await this . queue . add ( 'connectionSyncJob' , {
62
63
connectionId : connection . id ,
64
+ connectionName : connection . name ,
63
65
orgId : connection . orgId ,
64
66
config : connectionConfig ,
65
67
} ) ;
66
- this . logger . info ( `Added job to queue for connection ${ connection . id } ` ) ;
68
+ this . logger . info ( `Added job to queue for connection ${ connection . name } (id: ${ connection . id } ) ` ) ;
67
69
} ) . catch ( ( err : unknown ) => {
68
- this . logger . error ( `Failed to add job to queue for connection ${ connection . id } : ${ err } ` ) ;
70
+ this . logger . error ( `Failed to add job to queue for connection ${ connection . name } (id: ${ connection . id } ) : ${ err } ` ) ;
69
71
} ) ;
70
72
}
71
73
@@ -83,14 +85,18 @@ export class ConnectionManager implements IConnectionManager {
83
85
// (or if the date isn't set for some reason).
84
86
{
85
87
AND : [
86
- { OR : [
87
- { syncStatus : ConnectionSyncStatus . SYNCED } ,
88
- { syncStatus : ConnectionSyncStatus . SYNCED_WITH_WARNINGS } ,
89
- ] } ,
90
- { OR : [
91
- { syncedAt : null } ,
92
- { syncedAt : { lt : thresholdDate } } ,
93
- ] }
88
+ {
89
+ OR : [
90
+ { syncStatus : ConnectionSyncStatus . SYNCED } ,
91
+ { syncStatus : ConnectionSyncStatus . SYNCED_WITH_WARNINGS } ,
92
+ ]
93
+ } ,
94
+ {
95
+ OR : [
96
+ { syncedAt : null } ,
97
+ { syncedAt : { lt : thresholdDate } } ,
98
+ ]
99
+ }
94
100
]
95
101
}
96
102
]
@@ -103,7 +109,7 @@ export class ConnectionManager implements IConnectionManager {
103
109
}
104
110
105
111
private async runSyncJob ( job : Job < JobPayload > ) : Promise < JobResult > {
106
- const { config, orgId } = job . data ;
112
+ const { config, orgId, connectionName } = job . data ;
107
113
// @note : We aren't actually doing anything with this atm.
108
114
const abortController = new AbortController ( ) ;
109
115
@@ -120,7 +126,7 @@ export class ConnectionManager implements IConnectionManager {
120
126
Sentry . captureException ( e ) ;
121
127
throw e ;
122
128
}
123
-
129
+
124
130
// Reset the syncStatusMetadata to an empty object at the start of the sync job
125
131
await this . db . connection . update ( {
126
132
where : {
@@ -131,7 +137,7 @@ export class ConnectionManager implements IConnectionManager {
131
137
syncStatusMetadata : { }
132
138
}
133
139
} )
134
-
140
+
135
141
136
142
let result : {
137
143
repoData : RepoData [ ] ,
@@ -167,7 +173,7 @@ export class ConnectionManager implements IConnectionManager {
167
173
}
168
174
} ) ( ) ;
169
175
} catch ( err ) {
170
- this . logger . error ( `Failed to compile repo data for connection ${ job . data . connectionId } : ${ err } ` ) ;
176
+ this . logger . error ( `Failed to compile repo data for connection ${ job . data . connectionId } ( ${ connectionName } ) : ${ err } ` ) ;
171
177
Sentry . captureException ( err ) ;
172
178
173
179
if ( err instanceof BackendException ) {
@@ -191,7 +197,7 @@ export class ConnectionManager implements IConnectionManager {
191
197
syncStatusMetadata : { notFound }
192
198
}
193
199
} ) ;
194
-
200
+
195
201
// Filter out any duplicates by external_id and external_codeHostUrl.
196
202
repoData = repoData . filter ( ( repo , index , self ) => {
197
203
return index === self . findIndex ( r =>
@@ -218,7 +224,7 @@ export class ConnectionManager implements IConnectionManager {
218
224
}
219
225
} ) ;
220
226
const deleteDuration = performance . now ( ) - deleteStart ;
221
- this . logger . info ( `Deleted all RepoToConnection records for connection ${ job . data . connectionId } in ${ deleteDuration } ms` ) ;
227
+ this . logger . info ( `Deleted all RepoToConnection records for connection ${ connectionName } (id: ${ job . data . connectionId } ) in ${ deleteDuration } ms` ) ;
222
228
223
229
const totalUpsertStart = performance . now ( ) ;
224
230
for ( const repo of repoData ) {
@@ -235,10 +241,10 @@ export class ConnectionManager implements IConnectionManager {
235
241
create : repo ,
236
242
} )
237
243
const upsertDuration = performance . now ( ) - upsertStart ;
238
- this . logger . info ( `Upserted repo ${ repo . external_id } in ${ upsertDuration } ms` ) ;
244
+ this . logger . info ( `Upserted repo ${ repo . displayName } (id: ${ repo . external_id } ) in ${ upsertDuration } ms` ) ;
239
245
}
240
246
const totalUpsertDuration = performance . now ( ) - totalUpsertStart ;
241
- this . logger . info ( `Upserted ${ repoData . length } repos in ${ totalUpsertDuration } ms` ) ;
247
+ this . logger . info ( `Upserted ${ repoData . length } repos for connection ${ connectionName } (id: ${ job . data . connectionId } ) in ${ totalUpsertDuration } ms` ) ;
242
248
} , { timeout : env . CONNECTION_MANAGER_UPSERT_TIMEOUT_MS } ) ;
243
249
244
250
return {
@@ -248,18 +254,20 @@ export class ConnectionManager implements IConnectionManager {
248
254
249
255
250
256
private async onSyncJobCompleted ( job : Job < JobPayload > , result : JobResult ) {
251
- this . logger . info ( `Connection sync job ${ job . id } completed` ) ;
257
+ this . logger . info ( `Connection sync job for connection ${ job . data . connectionName } (id: ${ job . data . connectionId } , jobId: ${ job . id } ) completed` ) ;
252
258
const { connectionId } = job . data ;
253
259
254
260
let syncStatusMetadata : Record < string , unknown > = ( await this . db . connection . findUnique ( {
255
261
where : { id : connectionId } ,
256
262
select : { syncStatusMetadata : true }
257
263
} ) ) ?. syncStatusMetadata as Record < string , unknown > ?? { } ;
258
- const { notFound } = syncStatusMetadata as { notFound : {
259
- users : string [ ] ,
260
- orgs : string [ ] ,
261
- repos : string [ ] ,
262
- } } ;
264
+ const { notFound } = syncStatusMetadata as {
265
+ notFound : {
266
+ users : string [ ] ,
267
+ orgs : string [ ] ,
268
+ repos : string [ ] ,
269
+ }
270
+ } ;
263
271
264
272
await this . db . connection . update ( {
265
273
where : {
@@ -268,8 +276,8 @@ export class ConnectionManager implements IConnectionManager {
268
276
data : {
269
277
syncStatus :
270
278
notFound . users . length > 0 ||
271
- notFound . orgs . length > 0 ||
272
- notFound . repos . length > 0 ? ConnectionSyncStatus . SYNCED_WITH_WARNINGS : ConnectionSyncStatus . SYNCED ,
279
+ notFound . orgs . length > 0 ||
280
+ notFound . repos . length > 0 ? ConnectionSyncStatus . SYNCED_WITH_WARNINGS : ConnectionSyncStatus . SYNCED ,
273
281
syncedAt : new Date ( )
274
282
}
275
283
} )
@@ -281,7 +289,7 @@ export class ConnectionManager implements IConnectionManager {
281
289
}
282
290
283
291
private async onSyncJobFailed ( job : Job < JobPayload > | undefined , err : unknown ) {
284
- this . logger . info ( `Connection sync job failed with error: ${ err } ` ) ;
292
+ this . logger . info ( `Connection sync job for connection ${ job ?. data . connectionName } (id: ${ job ?. data . connectionId } , jobId: ${ job ?. id } ) failed with error: ${ err } ` ) ;
285
293
Sentry . captureException ( err , {
286
294
tags : {
287
295
connectionid : job ?. data . connectionId ,
@@ -312,7 +320,7 @@ export class ConnectionManager implements IConnectionManager {
312
320
}
313
321
} else {
314
322
syncStatusMetadata = {
315
- ...syncStatusMetadata ,
323
+ ...syncStatusMetadata ,
316
324
error : 'UNKNOWN' ,
317
325
}
318
326
}
0 commit comments