@@ -33,6 +33,7 @@ import {
33
33
type Relationship ,
34
34
type TextFileRef ,
35
35
type LastModifiedTimes ,
36
+ type JobInfo ,
36
37
} from '@cardstack/runtime-common' ;
37
38
import { Deferred } from '@cardstack/runtime-common/deferred' ;
38
39
import {
@@ -88,6 +89,7 @@ export class CurrentRun {
88
89
#render: Render ;
89
90
#realmURL: URL ;
90
91
#realmInfo?: RealmInfo ;
92
+ #jobInfo?: JobInfo ;
91
93
readonly stats : Stats = {
92
94
instancesIndexed : 0 ,
93
95
modulesIndexed : 0 ,
@@ -105,13 +107,15 @@ export class CurrentRun {
105
107
ignoreData = { } ,
106
108
renderCard,
107
109
render,
110
+ jobInfo,
108
111
} : {
109
112
realmURL : URL ;
110
113
reader : Reader ;
111
114
indexWriter : IndexWriter ;
112
115
ignoreData ?: Record < string , string > ;
113
116
renderCard : RenderCard ;
114
117
render : Render ;
118
+ jobInfo ?: JobInfo ;
115
119
} ) {
116
120
this . #indexWriter = indexWriter ;
117
121
this . #realmPaths = new RealmPaths ( realmURL ) ;
@@ -120,44 +124,51 @@ export class CurrentRun {
120
124
this . #ignoreData = ignoreData ;
121
125
this . #renderCard = renderCard ;
122
126
this . #render = render ;
127
+ this . #jobInfo = jobInfo ;
123
128
}
124
129
125
130
static async fromScratch ( current : CurrentRun ) : Promise < IndexResults > {
126
131
let start = Date . now ( ) ;
127
- log . debug ( `starting from scratch indexing` ) ;
132
+ log . debug (
133
+ `${ jobIdentity ( current . #jobInfo) } starting from scratch indexing` ,
134
+ ) ;
128
135
perfLog . debug (
129
- `starting from scratch indexing for realm ${ current . realmURL . href } ` ,
136
+ `${ jobIdentity ( current . #jobInfo ) } starting from scratch indexing for realm ${ current . realmURL . href } ` ,
130
137
) ;
131
138
current . #batch = await current . #indexWriter. createBatch ( current . realmURL ) ;
132
139
let invalidations : URL [ ] = [ ] ;
133
140
let mtimesStart = Date . now ( ) ;
134
141
let mtimes = await current . batch . getModifiedTimes ( ) ;
135
142
perfLog . debug (
136
- `completed getting index mtimes in ${ Date . now ( ) - mtimesStart } ms` ,
143
+ `${ jobIdentity ( current . #jobInfo ) } completed getting index mtimes in ${ Date . now ( ) - mtimesStart } ms` ,
137
144
) ;
138
145
let invalidateStart = Date . now ( ) ;
139
146
invalidations = (
140
147
await current . discoverInvalidations ( current . realmURL , mtimes )
141
148
) . map ( ( href ) => new URL ( href ) ) ;
142
149
perfLog . debug (
143
- `completed invalidations in ${ Date . now ( ) - invalidateStart } ms` ,
150
+ `${ jobIdentity ( current . #jobInfo ) } completed invalidations in ${ Date . now ( ) - invalidateStart } ms` ,
144
151
) ;
145
152
146
153
await current . whileIndexing ( async ( ) => {
147
154
let visitStart = Date . now ( ) ;
148
155
for ( let invalidation of invalidations ) {
149
156
await current . tryToVisit ( invalidation ) ;
150
157
}
151
- perfLog . debug ( `completed index visit in ${ Date . now ( ) - visitStart } ms` ) ;
158
+ perfLog . debug (
159
+ `${ jobIdentity ( current . #jobInfo) } completed index visit in ${ Date . now ( ) - visitStart } ms` ,
160
+ ) ;
152
161
let finalizeStart = Date . now ( ) ;
153
162
let { totalIndexEntries } = await current . batch . done ( ) ;
154
163
perfLog . debug (
155
- `completed index finalization in ${ Date . now ( ) - finalizeStart } ms` ,
164
+ `${ jobIdentity ( current . #jobInfo ) } completed index finalization in ${ Date . now ( ) - finalizeStart } ms` ,
156
165
) ;
157
166
current . stats . totalIndexEntries = totalIndexEntries ;
158
- log . debug ( `completed from scratch indexing in ${ Date . now ( ) - start } ms` ) ;
167
+ log . debug (
168
+ `${ jobIdentity ( current . #jobInfo) } completed from scratch indexing in ${ Date . now ( ) - start } ms` ,
169
+ ) ;
159
170
perfLog . debug (
160
- `completed from scratch indexing for realm ${
171
+ `${ jobIdentity ( current . #jobInfo ) } completed from scratch indexing for realm ${
161
172
current . realmURL . href
162
173
} in ${ Date . now ( ) - start } ms`,
163
174
) ;
@@ -180,7 +191,9 @@ export class CurrentRun {
180
191
} ,
181
192
) : Promise < IndexResults > {
182
193
let start = Date . now ( ) ;
183
- log . debug ( `starting from incremental indexing for ${ url . href } ` ) ;
194
+ log . debug (
195
+ `${ jobIdentity ( current . #jobInfo) } starting from incremental indexing for ${ url . href } ` ,
196
+ ) ;
184
197
185
198
current . #batch = await current . #indexWriter. createBatch ( current . realmURL ) ;
186
199
let invalidations = ( await current . batch . invalidate ( url ) ) . map (
@@ -200,7 +213,7 @@ export class CurrentRun {
200
213
current . stats . totalIndexEntries = totalIndexEntries ;
201
214
202
215
log . debug (
203
- `completed incremental indexing for ${ url . href } in ${
216
+ `${ jobIdentity ( current . #jobInfo ) } completed incremental indexing for ${ url . href } in ${
204
217
Date . now ( ) - start
205
218
} ms`,
206
219
) ;
@@ -217,7 +230,9 @@ export class CurrentRun {
217
230
await this . visitFile ( url ) ;
218
231
} catch ( err : any ) {
219
232
if ( isCardError ( err ) && err . status === 404 ) {
220
- log . info ( `tried to visit file ${ url . href } , but it no longer exists` ) ;
233
+ log . info (
234
+ `${ jobIdentity ( this . #jobInfo) } tried to visit file ${ url . href } , but it no longer exists` ,
235
+ ) ;
221
236
} else {
222
237
throw err ;
223
238
}
@@ -258,12 +273,16 @@ export class CurrentRun {
258
273
url : URL ,
259
274
indexMtimes : LastModifiedTimes ,
260
275
) : Promise < string [ ] > {
261
- log . debug ( `discovering invalidations in dir ${ url . href } ` ) ;
262
- perfLog . debug ( `discovering invalidations in dir ${ url . href } ` ) ;
276
+ log . debug (
277
+ `${ jobIdentity ( this . #jobInfo) } discovering invalidations in dir ${ url . href } ` ,
278
+ ) ;
279
+ perfLog . debug (
280
+ `${ jobIdentity ( this . #jobInfo) } discovering invalidations in dir ${ url . href } ` ,
281
+ ) ;
263
282
let mtimesStart = Date . now ( ) ;
264
283
let filesystemMtimes = await this . #reader. mtimes ( ) ;
265
284
perfLog . debug (
266
- `time to get file system mtimes ${ Date . now ( ) - mtimesStart } ms` ,
285
+ `${ jobIdentity ( this . #jobInfo ) } time to get file system mtimes ${ Date . now ( ) - mtimesStart } ms` ,
267
286
) ;
268
287
269
288
let ignoreFile = new URL ( '.gitignore' , url ) . href ;
@@ -278,7 +297,9 @@ export class CurrentRun {
278
297
this . #ignoreData[ url . href ] = ignorePatterns . content ;
279
298
}
280
299
} else {
281
- perfLog . debug ( `skip getting the ignore file--there is nothing to ignore` ) ;
300
+ perfLog . debug (
301
+ `${ jobIdentity ( this . #jobInfo) } skip getting the ignore file--there is nothing to ignore` ,
302
+ ) ;
282
303
}
283
304
284
305
let invalidationList : string [ ] = [ ] ;
@@ -314,7 +335,7 @@ export class CurrentRun {
314
335
await this . batch . invalidate ( new URL ( invalidationURL ) ) ;
315
336
}
316
337
perfLog . debug (
317
- `time to invalidate ${ url } ${ Date . now ( ) - invalidationStart } ms` ,
338
+ `${ jobIdentity ( this . #jobInfo ) } time to invalidate ${ url } ${ Date . now ( ) - invalidationStart } ms` ,
318
339
) ;
319
340
return this . batch . invalidations ;
320
341
}
@@ -327,7 +348,7 @@ export class CurrentRun {
327
348
return ;
328
349
}
329
350
let start = Date . now ( ) ;
330
- log . debug ( `begin visiting file ${ url . href } ` ) ;
351
+ log . debug ( `${ jobIdentity ( this . #jobInfo ) } begin visiting file ${ url . href } ` ) ;
331
352
let localPath : string ;
332
353
try {
333
354
localPath = this . #realmPaths. local ( url ) ;
@@ -336,7 +357,7 @@ export class CurrentRun {
336
357
// graph cross a realm just skip over the file. it will be out
337
358
// of date, but such is life...
338
359
log . debug (
339
- `Visit of ${ url . href } cannot be performed as it is in a different realm than the realm whose contents are being invalidated (${ this . realmURL . href } )` ,
360
+ `${ jobIdentity ( this . #jobInfo ) } Visit of ${ url . href } cannot be performed as it is in a different realm than the realm whose contents are being invalidated (${ this . realmURL . href } )` ,
340
361
) ;
341
362
return ;
342
363
}
@@ -365,13 +386,15 @@ export class CurrentRun {
365
386
let { data } = JSON . parse ( content ) ;
366
387
resource = data ;
367
388
} catch ( e ) {
368
- log . warn ( `unable to parse ${ url . href } as card JSON` ) ;
389
+ log . warn (
390
+ `${ jobIdentity ( this . #jobInfo) } unable to parse ${ url . href } as card JSON` ,
391
+ ) ;
369
392
}
370
393
371
394
if ( resource && isCardResource ( resource ) ) {
372
395
if ( lastModified == null ) {
373
396
log . warn (
374
- `No lastModified date available for ${ url . href } , using current time` ,
397
+ `${ jobIdentity ( this . #jobInfo ) } No lastModified date available for ${ url . href } , using current time` ,
375
398
) ;
376
399
lastModified = unixTime ( Date . now ( ) ) ;
377
400
}
@@ -386,7 +409,9 @@ export class CurrentRun {
386
409
}
387
410
}
388
411
}
389
- log . debug ( `completed visiting file ${ url . href } in ${ Date . now ( ) - start } ms` ) ;
412
+ log . debug (
413
+ `${ jobIdentity ( this . #jobInfo) } completed visiting file ${ url . href } in ${ Date . now ( ) - start } ms` ,
414
+ ) ;
390
415
}
391
416
392
417
private async indexModule ( url : URL , ref : TextFileRef ) : Promise < void > {
@@ -395,7 +420,7 @@ export class CurrentRun {
395
420
} catch ( err : any ) {
396
421
this . stats . moduleErrors ++ ;
397
422
log . warn (
398
- `encountered error loading module "${ url . href } ": ${ err . message } ` ,
423
+ `${ jobIdentity ( this . #jobInfo ) } encountered error loading module "${ url . href } ": ${ err . message } ` ,
399
424
) ;
400
425
let deps = await (
401
426
await this . loaderService . loader . getConsumedModules ( url . href )
@@ -413,7 +438,9 @@ export class CurrentRun {
413
438
}
414
439
415
440
if ( ref . isShimmed ) {
416
- log . debug ( `skipping indexing of shimmed module ${ url . href } ` ) ;
441
+ log . debug (
442
+ `${ jobIdentity ( this . #jobInfo) } skipping indexing of shimmed module ${ url . href } ` ,
443
+ ) ;
417
444
return ;
418
445
}
419
446
let consumes = (
@@ -650,7 +677,7 @@ export class CurrentRun {
650
677
throw err ;
651
678
}
652
679
log . warn (
653
- `encountered error indexing card instance ${ path } : ${ error . error . message } ` ,
680
+ `${ jobIdentity ( this . #jobInfo ) } encountered error indexing card instance ${ path } : ${ error . error . message } ` ,
654
681
) ;
655
682
await this . updateEntry ( instanceURL , error ) ;
656
683
}
@@ -811,3 +838,10 @@ function getDisplayName(card: typeof CardDef) {
811
838
return card . displayName ;
812
839
}
813
840
}
841
+
842
+ function jobIdentity ( jobInfo ?: JobInfo ) : string {
843
+ if ( ! jobInfo ) {
844
+ return `[no job identity]` ;
845
+ }
846
+ return `[job: ${ jobInfo . jobId } ] [jobReservation: ${ jobInfo . reservationId } ]` ;
847
+ }
0 commit comments