Skip to content

Instantly share code, notes, and snippets.

@yatishbalaji
Last active March 17, 2021 05:28
Show Gist options
  • Select an option

  • Save yatishbalaji/56ceffa48c928aec1e2b8ca1cf532d54 to your computer and use it in GitHub Desktop.

Select an option

Save yatishbalaji/56ceffa48c928aec1e2b8ca1cf532d54 to your computer and use it in GitHub Desktop.
node cron runner
#!/usr/bin/env node
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '.env') });
const program = require('commander');
let cron;
let main;
program
.version('0.0.1')
.usage('<cmd> [options]')
.arguments('<cmd> [command]')
.action((cmd, command = 'main') => ([cron, main] = [cmd, command]))
.parse(process.argv);
if (!cron) {
program.outputHelp();
process.exit(1);
}
const Task = require(`./server/crons/${cron}`);
new Task()[main]().then(() => process.exit(0), () => process.exit(1));
// Put cron files in ./server/crons/ directory and this file in home dir of project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment