(
reason: StopReason,
trigger: LifecycleTrigger,
)
| 45 | } |
| 46 | |
| 47 | private async requestStop( |
| 48 | reason: StopReason, |
| 49 | trigger: LifecycleTrigger, |
| 50 | ): Promise<CommandResult> { |
| 51 | if (this.stopReason) { |
| 52 | const message = |
| 53 | this.stopReason === "restart" |
| 54 | ? "Restart already in progress." |
| 55 | : "Shutdown already in progress."; |
| 56 | return { success: true, message }; |
| 57 | } |
| 58 | |
| 59 | this.stopReason = reason; |
| 60 | console.log(`[Lifecycle] ${reason} requested via ${trigger}`); |
| 61 | |
| 62 | setTimeout(() => { |
| 63 | void this.gracefulStopAndExit(reason); |
| 64 | }, 50); |
| 65 | |
| 66 | return { |
| 67 | success: true, |
| 68 | message: reason === "restart" ? "Restarting..." : "Shutting down...", |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | private async gracefulStopAndExit(reason: StopReason): Promise<void> { |
| 73 | try { |
no test coverage detected