* Terminate all workers and answer any outstanding calls gracefully. A worker * still starting up is terminated once it has started (see * WORKER_START_SETTLE_MS); outstanding calls are answered first. A retired * worker still on its way out is waited for, not left to end with the process.
()
| 509 | * worker still on its way out is waited for, not left to end with the process. |
| 510 | */ |
| 511 | async destroy(): Promise<void> { |
| 512 | if (this.destroyed) return; |
| 513 | this.destroyed = true; |
| 514 | this.clearIdleShrink(); |
| 515 | const ws = [...this.workers]; |
| 516 | this.workers.clear(); |
| 517 | this.pendingWorkers.clear(); |
| 518 | this.idle = []; |
| 519 | for (const job of [...this.inflight.values(), ...this.queue]) { |
| 520 | this.settle(job, { isError: true, content: [{ type: 'text', text: 'codegraph is shutting down; retry shortly.' }] }); |
| 521 | } |
| 522 | this.inflight.clear(); |
| 523 | this.queue = []; |
| 524 | await Promise.all([ |
| 525 | ...ws.map((w) => this.terminateStarted(w)), |
| 526 | ...[...this.retiring.values()].map((retirement) => retirement.gone), |
| 527 | ]); |
| 528 | } |
| 529 | } |
no test coverage detected