* 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.
()
| 594 | * worker still on its way out is waited for, not left to end with the process. |
| 595 | */ |
| 596 | async destroy(): Promise<void> { |
| 597 | if (this.destroyed) return; |
| 598 | this.destroyed = true; |
| 599 | this.clearIdleShrink(); |
| 600 | const ws = [...this.workers]; |
| 601 | this.workers.clear(); |
| 602 | this.pendingWorkers.clear(); |
| 603 | this.idle = []; |
| 604 | for (const job of [...this.inflight.values(), ...this.queue]) { |
| 605 | this.settle(job, { isError: true, content: [{ type: 'text', text: 'codegraph is shutting down; retry shortly.' }] }); |
| 606 | } |
| 607 | this.inflight.clear(); |
| 608 | this.queue = []; |
| 609 | await Promise.all([ |
| 610 | ...ws.map((w) => this.terminateStarted(w)), |
| 611 | ...[...this.retiring.values()].map((retirement) => retirement.gone), |
| 612 | ]); |
| 613 | } |
| 614 | } |