plantr 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +383 -221
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/create-seeder-instance.d.ts +76 -10
- package/dist/src/create-seeder-instance.d.ts.map +1 -1
- package/dist/src/dependency-resolver.d.ts +5 -4
- package/dist/src/dependency-resolver.d.ts.map +1 -1
- package/dist/src/errors.d.ts +18 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/formatting.d.ts +16 -0
- package/dist/src/formatting.d.ts.map +1 -1
- package/dist/src/map-with-limit.d.ts +19 -0
- package/dist/src/map-with-limit.d.ts.map +1 -0
- package/dist/src/run-seeders.d.ts +39 -8
- package/dist/src/run-seeders.d.ts.map +1 -1
- package/dist/src/signals.d.ts +9 -0
- package/dist/src/signals.d.ts.map +1 -0
- package/dist/src/step.d.ts +15 -0
- package/dist/src/step.d.ts.map +1 -1
- package/dist/src/types.d.ts +7 -0
- package/dist/src/types.d.ts.map +1 -1
- package/index.ts +5 -0
- package/package.json +1 -1
- package/readme.md +161 -21
- package/src/cli.ts +4 -13
- package/src/create-seeder-instance.ts +119 -21
- package/src/dependency-resolver.ts +5 -4
- package/src/errors.ts +29 -0
- package/src/formatting.ts +32 -1
- package/src/map-with-limit.ts +48 -0
- package/src/run-seeders.ts +304 -205
- package/src/signals.ts +54 -0
- package/src/step.ts +30 -4
- package/src/types.ts +7 -0
package/src/run-seeders.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { resolveDependencyOrder, UnknownSeederError } from './dependency-resolver.js'
|
|
2
|
+
import { SeedUsageError } from './errors.js'
|
|
2
3
|
import {
|
|
4
|
+
printCleanupErrors,
|
|
3
5
|
printConcurrentComplete,
|
|
4
6
|
printConcurrentSkipped,
|
|
5
7
|
printErrors,
|
|
8
|
+
printFreshReset,
|
|
6
9
|
printResultsTable,
|
|
7
10
|
printSeederComplete,
|
|
8
11
|
printSeederHeader,
|
|
@@ -11,6 +14,7 @@ import {
|
|
|
11
14
|
printSummary,
|
|
12
15
|
} from './formatting.js'
|
|
13
16
|
import { enterSeeding, exitSeeding } from './seeding-state.js'
|
|
17
|
+
import { onTerminationSignal } from './signals.js'
|
|
14
18
|
import type { StepRecord } from './step.js'
|
|
15
19
|
import type {
|
|
16
20
|
MaybePromise,
|
|
@@ -33,16 +37,48 @@ export type SeederScopeHandle = {
|
|
|
33
37
|
run: <T>(fn: () => Promise<T>) => Promise<T>
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
/** Passed to `setup`, for resources it acquires one at a time */
|
|
41
|
+
export type SetupHelpers = {
|
|
42
|
+
/**
|
|
43
|
+
* Register the cleanup for a resource right after acquiring it. Deferred cleanups run
|
|
44
|
+
* after `teardown`, last registered first, and also when `setup` throws after
|
|
45
|
+
* registering them (when `teardown` does not run, because there are no resources).
|
|
46
|
+
*/
|
|
47
|
+
defer: (cleanup: () => MaybePromise<void>) => void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Passed to `onFresh`: which seeders of this run ignore their cached steps */
|
|
51
|
+
export type FreshRun<TResources = undefined> = {
|
|
52
|
+
/** What `setup` returned */
|
|
53
|
+
resources: TResources
|
|
54
|
+
/** Names of the seeders in this run that run fresh, in run order (never empty) */
|
|
55
|
+
seeders: readonly string[]
|
|
56
|
+
/**
|
|
57
|
+
* Whether every registered seeder runs, and runs fresh (`fresh: true` without `only`,
|
|
58
|
+
* or CLI `--fresh` without seeder names). Only then is wiping the whole target safe:
|
|
59
|
+
* otherwise seeders outside `seeders` keep replaying cached ids of what they created.
|
|
60
|
+
*/
|
|
61
|
+
all: boolean
|
|
62
|
+
}
|
|
63
|
+
|
|
36
64
|
/**
|
|
37
65
|
* Internal configuration used by the runner.
|
|
38
66
|
* This is created by `createSeederInstance` and includes the wrapped context factory.
|
|
39
67
|
*/
|
|
40
|
-
export type InternalSeederConfig<TContext> = {
|
|
41
|
-
/** Factory function that creates the full context; called once, after
|
|
42
|
-
context: () => MaybePromise<TContext>
|
|
43
|
-
/**
|
|
68
|
+
export type InternalSeederConfig<TContext, TResources = undefined> = {
|
|
69
|
+
/** Factory function that creates the full context; called once, after setup */
|
|
70
|
+
context: (resources: TResources) => MaybePromise<TContext>
|
|
71
|
+
/** Acquires the run's resources, after onBeforeAll; its return value reaches context and teardown */
|
|
72
|
+
setup?: ((helpers: SetupHelpers) => MaybePromise<TResources>) | undefined
|
|
73
|
+
/** Releases what setup returned; runs whenever setup returned, also on failure and SIGINT/SIGTERM */
|
|
74
|
+
teardown?: ((resources: TResources) => MaybePromise<void>) | undefined
|
|
75
|
+
/** Called once after setup, before the cache preload (createSeederInstance builds its cache here) */
|
|
76
|
+
prepare?: ((resources: TResources) => MaybePromise<void>) | undefined
|
|
77
|
+
/** Called after prepare and before the cache preload when at least one seeder of the run is fresh */
|
|
78
|
+
onFresh?: ((run: FreshRun<TResources>) => MaybePromise<void>) | undefined
|
|
79
|
+
/** Called once after setup and onFresh to preload step cache entries */
|
|
44
80
|
preloadCache?: (() => MaybePromise<void>) | undefined
|
|
45
|
-
/** Called once before onAfterAll to flush buffered step cache writes
|
|
81
|
+
/** Called once before onAfterAll to flush buffered step cache writes */
|
|
46
82
|
flushCache?: (() => MaybePromise<void>) | undefined
|
|
47
83
|
/** Called before each seeder runs (legacy sequential hook); may return the record its steps fill */
|
|
48
84
|
beforeSeeder?: ((name: string, options: { fresh: boolean }) => StepRecord | undefined) | undefined
|
|
@@ -54,7 +90,7 @@ export type InternalSeederConfig<TContext> = {
|
|
|
54
90
|
bannerName?: string | undefined
|
|
55
91
|
/** Database URL the run writes to; non-local hosts are refused unless allowRemote */
|
|
56
92
|
target?: (() => string | undefined) | undefined
|
|
57
|
-
/** Called before the context
|
|
93
|
+
/** Called before setup and the context */
|
|
58
94
|
onBeforeAll?: (() => MaybePromise<void>) | undefined
|
|
59
95
|
/** Called after all seeders complete, also when a seeder or the context factory throws */
|
|
60
96
|
onAfterAll?: ((ctx: TContext | undefined) => MaybePromise<void>) | undefined
|
|
@@ -63,7 +99,7 @@ export type InternalSeederConfig<TContext> = {
|
|
|
63
99
|
/**
|
|
64
100
|
* Error thrown when a run would write to a database that is not local
|
|
65
101
|
*/
|
|
66
|
-
export class SeedTargetError extends
|
|
102
|
+
export class SeedTargetError extends SeedUsageError {
|
|
67
103
|
constructor(label: string) {
|
|
68
104
|
super(
|
|
69
105
|
`Refusing to seed ${label}: it is not a local database. Pass allowRemote (CLI: --allow-remote) to seed it on purpose.`,
|
|
@@ -140,11 +176,12 @@ export function describeTarget(target: string): TargetDescription {
|
|
|
140
176
|
*/
|
|
141
177
|
export async function runSeedersCore<
|
|
142
178
|
TContext,
|
|
179
|
+
TResources = undefined,
|
|
143
180
|
const TSeeders extends readonly SeederAny[] = readonly SeederAny[],
|
|
144
181
|
const TOptions extends RunSeedersOptions = RunSeedersOptions,
|
|
145
182
|
>(
|
|
146
183
|
seeders: TSeeders,
|
|
147
|
-
config: InternalSeederConfig<TContext>,
|
|
184
|
+
config: InternalSeederConfig<TContext, TResources>,
|
|
148
185
|
options: TOptions = {} as TOptions,
|
|
149
186
|
): Promise<RunSeedersResult<TSeeders, TOptions>> {
|
|
150
187
|
const {
|
|
@@ -155,6 +192,7 @@ export async function runSeedersCore<
|
|
|
155
192
|
fresh = false,
|
|
156
193
|
allowRemote = false,
|
|
157
194
|
concurrency = 1,
|
|
195
|
+
handleSignals = true,
|
|
158
196
|
} = options
|
|
159
197
|
|
|
160
198
|
if (
|
|
@@ -207,7 +245,50 @@ export async function runSeedersCore<
|
|
|
207
245
|
const failedSeeders = new Set<string>()
|
|
208
246
|
const concurrent = concurrency > 1
|
|
209
247
|
|
|
248
|
+
// Lifecycle state, read by the cleanup that runs on success, failure and SIGINT/SIGTERM
|
|
249
|
+
let beforeAllDone = false
|
|
250
|
+
let acquired: { resources: TResources } | undefined
|
|
251
|
+
let prepared = false
|
|
252
|
+
let ctx: TContext | undefined
|
|
253
|
+
let interrupted = false
|
|
254
|
+
const deferred: (() => MaybePromise<void>)[] = []
|
|
255
|
+
|
|
256
|
+
let cleanup: Promise<unknown[]> | undefined
|
|
257
|
+
const runCleanup = (): Promise<unknown[]> => {
|
|
258
|
+
cleanup ??= (async () => {
|
|
259
|
+
const errors: unknown[] = []
|
|
260
|
+
const attempt = async (fn: () => MaybePromise<void>) => {
|
|
261
|
+
try {
|
|
262
|
+
await fn()
|
|
263
|
+
} catch (error) {
|
|
264
|
+
errors.push(error)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (prepared && config.flushCache) await attempt(config.flushCache)
|
|
268
|
+
if (beforeAllDone && config.onAfterAll) {
|
|
269
|
+
const onAfterAll = config.onAfterAll
|
|
270
|
+
await attempt(() => onAfterAll(ctx))
|
|
271
|
+
}
|
|
272
|
+
if (acquired && config.teardown) {
|
|
273
|
+
const { teardown } = config
|
|
274
|
+
const { resources } = acquired
|
|
275
|
+
await attempt(() => teardown(resources))
|
|
276
|
+
}
|
|
277
|
+
for (const release of deferred.splice(0).reverse()) await attempt(release)
|
|
278
|
+
return errors
|
|
279
|
+
})()
|
|
280
|
+
return cleanup
|
|
281
|
+
}
|
|
282
|
+
|
|
210
283
|
enterSeeding()
|
|
284
|
+
const unregisterSignals = handleSignals
|
|
285
|
+
? onTerminationSignal(async () => {
|
|
286
|
+
interrupted = true
|
|
287
|
+
printCleanupErrors(await runCleanup())
|
|
288
|
+
})
|
|
289
|
+
: () => {}
|
|
290
|
+
|
|
291
|
+
let bodyError: { error: unknown } | undefined
|
|
211
292
|
try {
|
|
212
293
|
if (verbose) {
|
|
213
294
|
printStartBanner({
|
|
@@ -223,247 +304,265 @@ export async function runSeedersCore<
|
|
|
223
304
|
if (config.onBeforeAll) {
|
|
224
305
|
await config.onBeforeAll()
|
|
225
306
|
}
|
|
307
|
+
beforeAllDone = true
|
|
226
308
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
309
|
+
const resources = config.setup
|
|
310
|
+
? await config.setup({ defer: (release) => deferred.push(release) })
|
|
311
|
+
: (undefined as TResources)
|
|
312
|
+
acquired = { resources }
|
|
232
313
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
314
|
+
if (config.prepare) {
|
|
315
|
+
await config.prepare(resources)
|
|
316
|
+
}
|
|
317
|
+
prepared = true
|
|
236
318
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
319
|
+
const freshSeeders = orderedNames.filter(isFresh)
|
|
320
|
+
if (config.onFresh && freshSeeders.length > 0) {
|
|
321
|
+
const all = freshSeeders.length === seederMap.size
|
|
322
|
+
if (verbose) printFreshReset(freshSeeders, all)
|
|
323
|
+
await config.onFresh({ resources, seeders: freshSeeders, all })
|
|
324
|
+
}
|
|
241
325
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
record: config.beforeSeeder?.(name, { fresh: isFresh(name) }),
|
|
246
|
-
run: (fn) => fn(),
|
|
247
|
-
}
|
|
326
|
+
if (config.preloadCache) {
|
|
327
|
+
await config.preloadCache()
|
|
328
|
+
}
|
|
248
329
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
330
|
+
// Create context once for all seeders
|
|
331
|
+
ctx = await config.context(resources)
|
|
332
|
+
const activeCtx = ctx
|
|
253
333
|
|
|
254
|
-
|
|
334
|
+
const executeSeeder = async (name: string): Promise<boolean> => {
|
|
335
|
+
const idx = resultIndex.get(name)
|
|
336
|
+
const seeder = seederMap.get(name)
|
|
337
|
+
if (idx === undefined || !seeder) return true
|
|
255
338
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
results[idx] = {
|
|
262
|
-
name,
|
|
263
|
-
status: 'completed',
|
|
264
|
-
durationMs,
|
|
265
|
-
output,
|
|
266
|
-
cachedSteps: scopeHandle.record?.cachedSteps ?? [],
|
|
339
|
+
const scopeHandle: SeederScopeHandle = config.createSeederScope
|
|
340
|
+
? config.createSeederScope({ name, fresh: isFresh(name), concurrent })
|
|
341
|
+
: {
|
|
342
|
+
record: config.beforeSeeder?.(name, { fresh: isFresh(name) }),
|
|
343
|
+
run: (fn) => fn(),
|
|
267
344
|
}
|
|
268
345
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
346
|
+
const deps: Record<string, unknown> = {}
|
|
347
|
+
for (const depName of seeder.dependsOn) {
|
|
348
|
+
deps[depName] = outputs[depName]
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const startTime = performance.now()
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
const output = await scopeHandle.run(async () => seeder.run(activeCtx, deps))
|
|
355
|
+
const durationMs = Math.round(performance.now() - startTime)
|
|
356
|
+
|
|
357
|
+
outputs[name] = output
|
|
358
|
+
results[idx] = {
|
|
359
|
+
name,
|
|
360
|
+
status: 'completed',
|
|
361
|
+
durationMs,
|
|
362
|
+
output,
|
|
363
|
+
cachedSteps: scopeHandle.record?.cachedSteps ?? [],
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (verbose) {
|
|
367
|
+
if (concurrent) {
|
|
368
|
+
printConcurrentComplete(name, durationMs, true)
|
|
369
|
+
} else {
|
|
370
|
+
printSeederComplete(durationMs, true)
|
|
292
371
|
}
|
|
293
|
-
|
|
372
|
+
}
|
|
373
|
+
return true
|
|
374
|
+
} catch (error) {
|
|
375
|
+
const durationMs = Math.round(performance.now() - startTime)
|
|
376
|
+
const err = error instanceof Error ? error : new Error(String(error))
|
|
377
|
+
const failedStep =
|
|
378
|
+
scopeHandle.record?.failed && scopeHandle.record.failed.error === error
|
|
379
|
+
? scopeHandle.record.failed.step
|
|
380
|
+
: undefined
|
|
381
|
+
|
|
382
|
+
results[idx] = {
|
|
383
|
+
name,
|
|
384
|
+
status: 'failed',
|
|
385
|
+
durationMs,
|
|
386
|
+
error: err,
|
|
387
|
+
...(failedStep !== undefined ? { failedStep } : {}),
|
|
388
|
+
cachedSteps: scopeHandle.record?.cachedSteps ?? [],
|
|
389
|
+
}
|
|
390
|
+
failedSeeders.add(name)
|
|
294
391
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
392
|
+
if (verbose) {
|
|
393
|
+
if (concurrent) {
|
|
394
|
+
printConcurrentComplete(name, durationMs, false)
|
|
395
|
+
} else {
|
|
396
|
+
printSeederComplete(durationMs, false)
|
|
301
397
|
}
|
|
302
|
-
return false
|
|
303
398
|
}
|
|
399
|
+
return false
|
|
304
400
|
}
|
|
401
|
+
}
|
|
305
402
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
403
|
+
if (!concurrent) {
|
|
404
|
+
// Sequential execution in topological order
|
|
405
|
+
for (let i = 0; i < orderedNames.length; i++) {
|
|
406
|
+
// After SIGINT/SIGTERM, start nothing new while teardown runs
|
|
407
|
+
if (interrupted) break
|
|
408
|
+
const name = orderedNames[i]
|
|
409
|
+
if (!name) continue
|
|
410
|
+
const seeder = seederMap.get(name)
|
|
411
|
+
if (!seeder) continue
|
|
412
|
+
|
|
413
|
+
if (continueOnFailure) {
|
|
414
|
+
const failedDeps = seeder.dependsOn.filter((dep) => failedSeeders.has(dep))
|
|
415
|
+
if (failedDeps.length > 0) {
|
|
416
|
+
results[i] = { name, status: 'skipped', failedDeps }
|
|
417
|
+
failedSeeders.add(name)
|
|
418
|
+
if (verbose) {
|
|
419
|
+
printSeederHeader(name, i, orderedNames.length, seeder.description)
|
|
420
|
+
printSeederSkipped(failedDeps)
|
|
324
421
|
}
|
|
422
|
+
continue
|
|
325
423
|
}
|
|
424
|
+
}
|
|
326
425
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
426
|
+
if (verbose) {
|
|
427
|
+
printSeederHeader(name, i, orderedNames.length, seeder.description)
|
|
428
|
+
}
|
|
330
429
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
430
|
+
const ok = await executeSeeder(name)
|
|
431
|
+
if (!ok && !continueOnFailure) {
|
|
432
|
+
break
|
|
335
433
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
434
|
+
}
|
|
435
|
+
} else if (orderedNames.length > 0) {
|
|
436
|
+
// Parallel DAG worker pool with critical-path (longest-downstream-chain-first) scheduling
|
|
437
|
+
const remainingDeps = new Map<string, number>()
|
|
438
|
+
const dependents = new Map<string, string[]>()
|
|
439
|
+
|
|
440
|
+
for (const name of orderedNames) {
|
|
441
|
+
remainingDeps.set(name, 0)
|
|
442
|
+
dependents.set(name, [])
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
for (const name of orderedNames) {
|
|
446
|
+
const seeder = seederMap.get(name)
|
|
447
|
+
if (!seeder) continue
|
|
448
|
+
const uniqueDeps = new Set(seeder.dependsOn)
|
|
449
|
+
remainingDeps.set(name, uniqueDeps.size)
|
|
450
|
+
for (const dep of uniqueDeps) {
|
|
451
|
+
dependents.get(dep)?.push(name)
|
|
344
452
|
}
|
|
453
|
+
}
|
|
345
454
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
455
|
+
// Compute critical-path height (longest chain of downstream dependents) in reverse topo order
|
|
456
|
+
const criticalHeight = new Map<string, number>()
|
|
457
|
+
for (let i = orderedNames.length - 1; i >= 0; i--) {
|
|
458
|
+
const name = orderedNames[i]!
|
|
459
|
+
let maxHeight = 0
|
|
460
|
+
for (const dependent of dependents.get(name) ?? []) {
|
|
461
|
+
const h = (criticalHeight.get(dependent) ?? 0) + 1
|
|
462
|
+
if (h > maxHeight) maxHeight = h
|
|
354
463
|
}
|
|
464
|
+
criticalHeight.set(name, maxHeight)
|
|
465
|
+
}
|
|
355
466
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
let maxHeight = 0
|
|
361
|
-
for (const dependent of dependents.get(name) ?? []) {
|
|
362
|
-
const h = (criticalHeight.get(dependent) ?? 0) + 1
|
|
363
|
-
if (h > maxHeight) maxHeight = h
|
|
364
|
-
}
|
|
365
|
-
criticalHeight.set(name, maxHeight)
|
|
467
|
+
const ready: string[] = []
|
|
468
|
+
for (const name of orderedNames) {
|
|
469
|
+
if (remainingDeps.get(name) === 0) {
|
|
470
|
+
ready.push(name)
|
|
366
471
|
}
|
|
472
|
+
}
|
|
367
473
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
474
|
+
const popHighestPriority = (): string => {
|
|
475
|
+
let bestIdx = 0
|
|
476
|
+
let bestHeight = criticalHeight.get(ready[0]!) ?? 0
|
|
477
|
+
let bestOrder = resultIndex.get(ready[0]!) ?? 0
|
|
478
|
+
for (let i = 1; i < ready.length; i++) {
|
|
479
|
+
const candidate = ready[i]!
|
|
480
|
+
const h = criticalHeight.get(candidate) ?? 0
|
|
481
|
+
const order = resultIndex.get(candidate) ?? 0
|
|
482
|
+
if (h > bestHeight || (h === bestHeight && order < bestOrder)) {
|
|
483
|
+
bestIdx = i
|
|
484
|
+
bestHeight = h
|
|
485
|
+
bestOrder = order
|
|
372
486
|
}
|
|
373
487
|
}
|
|
488
|
+
return ready.splice(bestIdx, 1)[0]!
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
await new Promise<void>((resolve) => {
|
|
492
|
+
let inFlight = 0
|
|
493
|
+
let stopped = false
|
|
494
|
+
|
|
495
|
+
const markSettled = (settledName: string) => {
|
|
496
|
+
const deps = dependents.get(settledName)
|
|
497
|
+
if (!deps) return
|
|
498
|
+
for (const dependent of deps) {
|
|
499
|
+
const next = (remainingDeps.get(dependent) ?? 1) - 1
|
|
500
|
+
remainingDeps.set(dependent, next)
|
|
501
|
+
if (next !== 0 || stopped) continue
|
|
502
|
+
|
|
503
|
+
const seeder = seederMap.get(dependent)
|
|
504
|
+
if (!seeder) continue
|
|
374
505
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
506
|
+
const failedDeps = seeder.dependsOn.filter((d) => failedSeeders.has(d))
|
|
507
|
+
if (failedDeps.length > 0) {
|
|
508
|
+
const idx = resultIndex.get(dependent)
|
|
509
|
+
if (idx !== undefined) {
|
|
510
|
+
results[idx] = { name: dependent, status: 'skipped', failedDeps }
|
|
511
|
+
}
|
|
512
|
+
failedSeeders.add(dependent)
|
|
513
|
+
if (verbose) {
|
|
514
|
+
printConcurrentSkipped(dependent, failedDeps)
|
|
515
|
+
}
|
|
516
|
+
markSettled(dependent)
|
|
517
|
+
} else {
|
|
518
|
+
ready.push(dependent)
|
|
387
519
|
}
|
|
388
520
|
}
|
|
389
|
-
return ready.splice(bestIdx, 1)[0]!
|
|
390
521
|
}
|
|
391
522
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const next = (remainingDeps.get(dependent) ?? 1) - 1
|
|
401
|
-
remainingDeps.set(dependent, next)
|
|
402
|
-
if (next !== 0 || stopped) continue
|
|
403
|
-
|
|
404
|
-
const seeder = seederMap.get(dependent)
|
|
405
|
-
if (!seeder) continue
|
|
406
|
-
|
|
407
|
-
const failedDeps = seeder.dependsOn.filter((d) => failedSeeders.has(d))
|
|
408
|
-
if (failedDeps.length > 0) {
|
|
409
|
-
const idx = resultIndex.get(dependent)
|
|
410
|
-
if (idx !== undefined) {
|
|
411
|
-
results[idx] = { name: dependent, status: 'skipped', failedDeps }
|
|
412
|
-
}
|
|
413
|
-
failedSeeders.add(dependent)
|
|
414
|
-
if (verbose) {
|
|
415
|
-
printConcurrentSkipped(dependent, failedDeps)
|
|
416
|
-
}
|
|
417
|
-
markSettled(dependent)
|
|
523
|
+
const schedule = () => {
|
|
524
|
+
while (!stopped && !interrupted && inFlight < concurrency && ready.length > 0) {
|
|
525
|
+
const name = popHighestPriority()
|
|
526
|
+
inFlight++
|
|
527
|
+
void executeSeeder(name).then((ok) => {
|
|
528
|
+
inFlight--
|
|
529
|
+
if (!ok && !continueOnFailure) {
|
|
530
|
+
stopped = true
|
|
418
531
|
} else {
|
|
419
|
-
|
|
532
|
+
markSettled(name)
|
|
420
533
|
}
|
|
421
|
-
|
|
534
|
+
schedule()
|
|
535
|
+
})
|
|
422
536
|
}
|
|
423
537
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const name = popHighestPriority()
|
|
427
|
-
inFlight++
|
|
428
|
-
void executeSeeder(name).then((ok) => {
|
|
429
|
-
inFlight--
|
|
430
|
-
if (!ok && !continueOnFailure) {
|
|
431
|
-
stopped = true
|
|
432
|
-
} else {
|
|
433
|
-
markSettled(name)
|
|
434
|
-
}
|
|
435
|
-
schedule()
|
|
436
|
-
})
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (inFlight === 0 && (stopped || ready.length === 0)) {
|
|
440
|
-
resolve()
|
|
441
|
-
}
|
|
538
|
+
if (inFlight === 0 && (stopped || interrupted || ready.length === 0)) {
|
|
539
|
+
resolve()
|
|
442
540
|
}
|
|
541
|
+
}
|
|
443
542
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
543
|
+
schedule()
|
|
544
|
+
})
|
|
545
|
+
}
|
|
447
546
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
} finally {
|
|
454
|
-
try {
|
|
455
|
-
if (config.flushCache) {
|
|
456
|
-
await config.flushCache()
|
|
457
|
-
}
|
|
458
|
-
} finally {
|
|
459
|
-
if (config.onAfterAll) {
|
|
460
|
-
await config.onAfterAll(ctx)
|
|
461
|
-
}
|
|
462
|
-
}
|
|
547
|
+
if (printResults) {
|
|
548
|
+
printResultsTable(results)
|
|
549
|
+
printErrors(results)
|
|
550
|
+
printSummary(results, performance.now() - runStartTime, concurrency)
|
|
463
551
|
}
|
|
552
|
+
} catch (error) {
|
|
553
|
+
bodyError = { error }
|
|
464
554
|
} finally {
|
|
555
|
+
const cleanupErrors = await runCleanup()
|
|
556
|
+
unregisterSignals()
|
|
465
557
|
exitSeeding()
|
|
558
|
+
if (bodyError) {
|
|
559
|
+
printCleanupErrors(cleanupErrors)
|
|
560
|
+
} else if (cleanupErrors.length > 0) {
|
|
561
|
+
printCleanupErrors(cleanupErrors.slice(1))
|
|
562
|
+
bodyError = { error: cleanupErrors[0] }
|
|
563
|
+
}
|
|
466
564
|
}
|
|
565
|
+
if (bodyError) throw bodyError.error
|
|
467
566
|
|
|
468
567
|
const hasFailure = results.some((r) => r.status === 'failed')
|
|
469
568
|
if (hasFailure) {
|