* 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.
()
| 522 | * worker still on its way out is waited for, not left to end with the process. |
| 523 | */ |
| 524 | async destroy(): Promise<void> { |
| 525 | if (this.destroyed) return; |
| 526 | this.destroyed = true; |
| 527 | this.clearIdleShrink(); |
| 528 | const ws = [...this.workers]; |
| 529 | this.workers.clear(); |
| 530 | this.pendingWorkers.clear(); |
| 531 | this.idle = []; |
| 532 | for (const job of [...this.inflight.values(), ...this.queue]) { |
| 533 | this.settle(job, { isError: true, content: [{ type: 'text', text: 'codegraph is shutting down; retry shortly.' }] }); |
| 534 | } |
| 535 | this.inflight.clear(); |
| 536 | this.queue = []; |
| 537 | await Promise.all([ |
| 538 | ...ws.map((w) => this.terminateStarted(w)), |
| 539 | ...[...this.retiring.values()].map((retirement) => retirement.gone), |
| 540 | ]); |
| 541 | } |
| 542 | } |