jerrywdlee / no-cron

A node.js based fake cron. Will run cron jobs with current environment variables.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no-cron

CircleCI Build Status Coverage Status Maintainability Test Coverage Known Vulnerabilities contributions welcome License: MPL 2.0 LICENSE 996.icu

A node.js based fake cron. Will run cron jobs with current environment variables.

Usage

Attention

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!

Run in Foreground

# 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`

Run as daemon

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

Docker usage

Some docker example in ./docker directory.

Docker

$ cd docker
$ docker build -t no-cron .
$ docker run no-cron

Docker Compose

$ 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.

Known issues

  • Errors when execute node.js scripts in a different version of node.js

LICENSE

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

About

A node.js based fake cron. Will run cron jobs with current environment variables.

License:Other


Languages

Language:JavaScript 90.0%Language:Dockerfile 10.0%