Skip to content

Commit

Permalink
Merge pull request #19 from theanupambista/main
Browse files Browse the repository at this point in the history
feat: added run command
  • Loading branch information
isarojdahal authored Sep 6, 2024
2 parents d3b024b + d57c53b commit 659e128
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ AWS_REGION=${region}`;
process.exit(1);
}

execSync("pnpm install && pnpm start");
// execSync("pnpm install && pnpm start");
});

program
Expand Down Expand Up @@ -342,4 +342,25 @@ program
}
});

program
.command("run")
.description("Run the backup process with cron scheduling")
.option("--cron <schedule>", "Cron schedule (default is once per day)")
.action((cmd) => {
// Check if .env file exists
if (!fs.existsSync(".env")) {
console.log(chalk.red("Environment variables file not found!"));
console.log(chalk.red("Please run the install command first!"));
process.exit(1);
}
const cronSchedule = cmd.cron || "0 0 * * *"; // Default: once per day

execSync(`pm2 start run-ts.sh --name dbbackup --cron "${cronSchedule}"`);
execSync("pm2 save");

console.log(
chalk.green(`Cron job scheduled with expression: ${cronSchedule}`)
);
});

program.parse(process.argv);
1 change: 1 addition & 0 deletions run-ts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ts-node -T src/index.ts

0 comments on commit 659e128

Please sign in to comment.