-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: force collie to exit when receiving second interrupt from user
this is consistent with the behavior of terraform/terragrunt
- Loading branch information
1 parent
e15aad1
commit d650f0f
Showing
1 changed file
with
19 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ import { CollieFoundationDoesNotExistError } from "./model/schemas/ModelValidato | |
import { makeTopLevelCommand } from "./commands/TopLevelCommand.ts"; | ||
import { registerInfoCommand } from "./commands/info.command.ts"; | ||
import { registerConfigCommand } from "./commands/config/config.command.ts"; | ||
import { DenoStdInternalError } from "https://deno.land/[email protected]/_util/assert.ts"; | ||
|
||
let shutdownRequested = 0; | ||
|
||
async function collie() { | ||
const program = makeTopLevelCommand() | ||
|
@@ -99,9 +102,22 @@ if (import.meta.main) { | |
} | ||
|
||
function gracefulShutdown(): void { | ||
shutdownRequested += 1; | ||
|
||
if (shutdownRequested == 1) { | ||
logWithBanner( | ||
"Interrupt received.\nPlease wait for collie shut down or data loss may occur.\nGracefully shutting down...", | ||
); | ||
} else { | ||
logWithBanner( | ||
"Two interrupts received, collie will now exit. Data loss may occur.", | ||
); | ||
Deno.exit(143); | ||
} | ||
} | ||
|
||
function logWithBanner(msg: string) { | ||
console.log("\n\n"); | ||
console.log( | ||
"Interrupt received.\nPlease wait for collie shut down or data loss may occur.\nGracefully shutting down...", | ||
); | ||
console.log(msg); | ||
console.log("\n\n"); | ||
} |