Skip to content

Commit

Permalink
feat: force collie to exit when receiving second interrupt from user
Browse files Browse the repository at this point in the history
this is consistent with the behavior of terraform/terragrunt
  • Loading branch information
JohannesRudolph committed Mar 25, 2024
1 parent e15aad1 commit 3f54ea1
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { makeTopLevelCommand } from "./commands/TopLevelCommand.ts";
import { registerInfoCommand } from "./commands/info.command.ts";
import { registerConfigCommand } from "./commands/config/config.command.ts";

let shutdownRequested = 0;

async function collie() {
const program = makeTopLevelCommand()
.name(CLI)
Expand Down Expand Up @@ -99,9 +101,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");
}

0 comments on commit 3f54ea1

Please sign in to comment.