@@ -20,6 +20,7 @@ const QUEUE_NAME = 'connectionSyncQueue';
2020
2121type JobPayload = {
2222 connectionId : number ,
23+ connectionName : string ,
2324 orgId : number ,
2425 config : ConnectionConfig ,
2526} ;
@@ -60,12 +61,13 @@ export class ConnectionManager implements IConnectionManager {
6061
6162 await this . queue . add ( 'connectionSyncJob' , {
6263 connectionId : connection . id ,
64+ connectionName : connection . name ,
6365 orgId : connection . orgId ,
6466 config : connectionConfig ,
6567 } ) ;
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 } ) ` ) ;
6769 } ) . 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 } ` ) ;
6971 } ) ;
7072 }
7173
@@ -83,14 +85,18 @@ export class ConnectionManager implements IConnectionManager {
8385 // (or if the date isn't set for some reason).
8486 {
8587 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+ }
94100 ]
95101 }
96102 ]
@@ -103,7 +109,7 @@ export class ConnectionManager implements IConnectionManager {
103109 }
104110
105111 private async runSyncJob ( job : Job < JobPayload > ) : Promise < JobResult > {
106- const { config, orgId } = job . data ;
112+ const { config, orgId, connectionName } = job . data ;
107113 // @note : We aren't actually doing anything with this atm.
108114 const abortController = new AbortController ( ) ;
109115
@@ -120,7 +126,7 @@ export class ConnectionManager implements IConnectionManager {
120126 Sentry . captureException ( e ) ;
121127 throw e ;
122128 }
123-
129+
124130 // Reset the syncStatusMetadata to an empty object at the start of the sync job
125131 await this . db . connection . update ( {
126132 where : {
@@ -131,7 +137,7 @@ export class ConnectionManager implements IConnectionManager {
131137 syncStatusMetadata : { }
132138 }
133139 } )
134-
140+
135141
136142 let result : {
137143 repoData : RepoData [ ] ,
@@ -167,7 +173,7 @@ export class ConnectionManager implements IConnectionManager {
167173 }
168174 } ) ( ) ;
169175 } 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 } ` ) ;
171177 Sentry . captureException ( err ) ;
172178
173179 if ( err instanceof BackendException ) {
@@ -191,7 +197,7 @@ export class ConnectionManager implements IConnectionManager {
191197 syncStatusMetadata : { notFound }
192198 }
193199 } ) ;
194-
200+
195201 // Filter out any duplicates by external_id and external_codeHostUrl.
196202 repoData = repoData . filter ( ( repo , index , self ) => {
197203 return index === self . findIndex ( r =>
@@ -218,7 +224,7 @@ export class ConnectionManager implements IConnectionManager {
218224 }
219225 } ) ;
220226 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` ) ;
222228
223229 const totalUpsertStart = performance . now ( ) ;
224230 for ( const repo of repoData ) {
@@ -235,10 +241,10 @@ export class ConnectionManager implements IConnectionManager {
235241 create : repo ,
236242 } )
237243 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` ) ;
239245 }
240246 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` ) ;
242248 } , { timeout : env . CONNECTION_MANAGER_UPSERT_TIMEOUT_MS } ) ;
243249
244250 return {
@@ -248,18 +254,20 @@ export class ConnectionManager implements IConnectionManager {
248254
249255
250256 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` ) ;
252258 const { connectionId } = job . data ;
253259
254260 let syncStatusMetadata : Record < string , unknown > = ( await this . db . connection . findUnique ( {
255261 where : { id : connectionId } ,
256262 select : { syncStatusMetadata : true }
257263 } ) ) ?. 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+ } ;
263271
264272 await this . db . connection . update ( {
265273 where : {
@@ -268,8 +276,8 @@ export class ConnectionManager implements IConnectionManager {
268276 data : {
269277 syncStatus :
270278 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 ,
273281 syncedAt : new Date ( )
274282 }
275283 } )
@@ -281,7 +289,7 @@ export class ConnectionManager implements IConnectionManager {
281289 }
282290
283291 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 } ` ) ;
285293 Sentry . captureException ( err , {
286294 tags : {
287295 connectionid : job ?. data . connectionId ,
@@ -312,7 +320,7 @@ export class ConnectionManager implements IConnectionManager {
312320 }
313321 } else {
314322 syncStatusMetadata = {
315- ...syncStatusMetadata ,
323+ ...syncStatusMetadata ,
316324 error : 'UNKNOWN' ,
317325 }
318326 }
0 commit comments