-
-
Save yatishbalaji/56ceffa48c928aec1e2b8ca1cf532d54 to your computer and use it in GitHub Desktop.
node cron runner
This file contains hidden or 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
| #!/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