(finalExitCode: number, flushTimeoutMs: number)
| 339 | let cleanupStarted = false; |
| 340 | let forcedShutdownTimer: NodeJS.Timeout | null = null; |
| 341 | const finishShutdown = (finalExitCode: number, flushTimeoutMs: number): void => { |
| 342 | if (cleanupStarted) { |
| 343 | return; |
| 344 | } |
| 345 | cleanupStarted = true; |
| 346 | if (forcedShutdownTimer) { |
| 347 | clearTimeout(forcedShutdownTimer); |
| 348 | forcedShutdownTimer = null; |
| 349 | } |
| 350 | void cleanupArtifacts() |
| 351 | .then( |
| 352 | (result) => { |
| 353 | if (result.errors.length > 0) { |
| 354 | log('error', `[Daemon] Cleanup failed: ${result.errors.join('; ')}`, { |
| 355 | sentry: true, |
| 356 | }); |
| 357 | return; |
| 358 | } |
| 359 | log('info', '[Daemon] Cleanup complete'); |
| 360 | }, |
| 361 | (error) => { |
| 362 | const message = error instanceof Error ? error.message : String(error); |
| 363 | log('error', `[Daemon] Cleanup failed: ${message}`, { sentry: true }); |
| 364 | }, |
| 365 | ) |
| 366 | .finally(() => { |
| 367 | void flushAndCloseSentry(flushTimeoutMs).finally(() => { |
| 368 | process.exit(finalExitCode); |
| 369 | }); |
| 370 | }); |
| 371 | }; |
| 372 | |
| 373 | forcedShutdownTimer = setTimeout(() => { |
| 374 | log('warn', '[Daemon] Forced shutdown after timeout'); |
no test coverage detected