A node.js based fake cron. Will run cron jobs with current environment variables.
Stop system's cron service before start no-cron
, or all cron jobs will be multiple executed.
# Stop system cron service
$ service cron stop
[FAIL] cron is not running ... failed!
# Need node.js v8+
$ git clone https://github.com/jerrywdlee/no-cron.git && cd no-cron
$ npm install
$ node cron # This will execute cronjobs in system crontab
$ node cron -f my_cron.txt # Execute cronjobs wrote in a file called `my_cron.txt`
Plz install pm2 or forever to daemonize no-cron
$ git clone https://github.com/jerrywdlee/no-cron.git && cd no-cron
$ npm i && npm i -g pm2
$ pm2 start cron.js
# OR
$ pm2 start cron.js -- -f my_cron.txt
Some docker example in ./docker
directory.
$ cd docker
$ docker build -t no-cron .
$ docker run no-cron
$ cd docker
$ docker-compose build
$ docker-compose up
Difference between THE Cron
The Crontab
in UNIX/LINUX will run command in an isolated condition. Environment variables such as timezone will be different between cron environment and current environment.
When using time-based job scheduler in docker containers most environment variables will not imported to cron's environment.
PS: Image node:10.15.3-alpine doesn't have this problem, but ruby:2.6.1 does.
Thus, most famous container IaaS providers such as Heroku, recommend users not to use cron inside containers.
But some legacy libraries and projects such as whenever provide easier ways to maintenance time-based job scheduler with in source codes.
So no-cron
will give a way to run cron jobs for legacy cron-based libraries or projects.
It will parse commands and schedules from crontab, and run them timely with environments as same as main projects.
For alpha stage, I just created a node.js based fack cron for my companies' Rails projects.
Next time, I'll refactor it by Golang or Rust.
- Errors when execute node.js scripts in a different version of node.js
This project is dual licensed under Anti 996 License & Mozilla Public License.
Click here for more info about Anti 996 Project.
Copyright (c) 2019 Jerry Lee