All Projects → node-cron → Node Cron

node-cron / Node Cron

Licence: isc
A simple cron-like job scheduler for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Cron

Quartznet
Quartz Enterprise Scheduler .NET
Stars: ✭ 4,825 (+133.77%)
Mutual labels:  cron, scheduled-jobs, scheduled-tasks
Shardingsphere Elasticjob Cloud
Stars: ✭ 248 (-87.98%)
Mutual labels:  cron, scheduled-jobs
Dkron
Dkron - Distributed, fault tolerant job scheduling system https://dkron.io
Stars: ✭ 2,930 (+41.96%)
Mutual labels:  cron, scheduled-jobs
Cronical
.NET-based cron daemon. Can replace Windows Services and Scheduled Tasks, typically for running service-like processes as part of an application suite - or just by itself.
Stars: ✭ 42 (-97.97%)
Mutual labels:  cron, scheduled-tasks
Hangfire.topshelf
Best practice for hangfire samples
Stars: ✭ 192 (-90.7%)
Mutual labels:  scheduled-jobs, scheduled-tasks
Cronscheduler.aspnetcore
Cron Scheduler for AspNetCore 2.x/3.x or DotNetCore 2.x/3.x Self-hosted
Stars: ✭ 100 (-95.16%)
Mutual labels:  cron, scheduled-jobs
arask
Automatic RAils taSKs.
Stars: ✭ 31 (-98.5%)
Mutual labels:  cron, cron-syntax
Sundial
A Light-weight Job Scheduling Framework
Stars: ✭ 230 (-88.86%)
Mutual labels:  cron, scheduled-jobs
Shardingsphere Elasticjob
Distributed scheduled job framework
Stars: ✭ 7,369 (+257.03%)
Mutual labels:  cron, scheduled-jobs
Chronos
Fault tolerant job scheduler for Mesos which handles dependencies and ISO8601 based schedules
Stars: ✭ 4,303 (+108.48%)
Mutual labels:  cron, scheduled-jobs
Schedex
Simple scheduling for Elixir
Stars: ✭ 173 (-91.62%)
Mutual labels:  scheduled-jobs, scheduled-tasks
Frame Scheduling
Asynchronous non-blocking running many tasks in JavaScript. Demo https://codesandbox.io/s/admiring-ride-jdoq0
Stars: ✭ 64 (-96.9%)
Mutual labels:  scheduled-jobs, scheduled-tasks
crontab
cron expression parser and executor for dotnet core.
Stars: ✭ 13 (-99.37%)
Mutual labels:  cron, scheduled-jobs
josk
🏃🤖 Scheduler and manager for jobs and tasks in node.js on multi-server and clusters setup
Stars: ✭ 27 (-98.69%)
Mutual labels:  cron, scheduled-jobs
Cronmon
PHP Web app to monitor cron/scheduled tasks
Stars: ✭ 55 (-97.34%)
Mutual labels:  cron, scheduled-tasks
Gcalcron
Schedule shell commands execution through Google Calendar
Stars: ✭ 81 (-96.08%)
Mutual labels:  cron, scheduled-tasks
Clockwerk
Job Scheduling Library
Stars: ✭ 104 (-94.96%)
Mutual labels:  cron
Dottask
Simple and easy go task framework, support loop & cron & queue
Stars: ✭ 124 (-93.99%)
Mutual labels:  cron
Sidekiq Cron
Scheduler / Cron for Sidekiq jobs
Stars: ✭ 1,383 (-32.99%)
Mutual labels:  scheduled-jobs
Mysqlbkup
Lightweight MySQL backup script in BASH
Stars: ✭ 129 (-93.75%)
Mutual labels:  cron

Node Cron

npm npm Coverage Status Code Climate Build Status Dependency Status devDependency Status Backers on Open Collective Sponsors on Open Collective

The node-cron module is tiny task scheduler in pure JavaScript for node.js based on GNU crontab. This module allows you to schedule task in node.js using full crontab syntax.

Need a job scheduler with support for worker threads and cron syntax? Try out the Bree job scheduler!

NPM

Getting Started

Install node-cron using npm:

$ npm install --save node-cron

Import node-cron and schedule a task:

var cron = require('node-cron');

cron.schedule('* * * * *', () => {
  console.log('running a task every minute');
});

Cron Syntax

This is a quick reference to cron syntax and also shows the options supported by node-cron.

Allowed fields

 # ┌────────────── second (optional)
 # │ ┌──────────── minute
 # │ │ ┌────────── hour
 # │ │ │ ┌──────── day of month
 # │ │ │ │ ┌────── month
 # │ │ │ │ │ ┌──── day of week
 # │ │ │ │ │ │
 # │ │ │ │ │ │
 # * * * * * *

Allowed values

field value
second 0-59
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names)
day of week 0-7 (or names, 0 or 7 are sunday)

Using multiples values

You may use multiples values separated by comma:

var cron = require('node-cron');

cron.schedule('1,2,4,5 * * * *', () => {
  console.log('running every minute 1, 2, 4 and 5');
});

Using ranges

You may also define a range of values:

var cron = require('node-cron');

cron.schedule('1-5 * * * *', () => {
  console.log('running every minute to 1 from 5');
});

Using step values

Step values can be used in conjunction with ranges, following a range with '/' and a number. e.g: 1-10/2 that is the same as 2,4,6,8,10. Steps are also permitted after an asterisk, so if you want to say “every two minutes”, just use */2.

var cron = require('node-cron');

cron.schedule('*/2 * * * *', () => {
  console.log('running a task every two minutes');
});

Using names

For month and week day you also may use names or short names. e.g:

var cron = require('node-cron');

cron.schedule('* * * January,September Sunday', () => {
  console.log('running on Sundays of January and September');
});

Or with short names:

var cron = require('node-cron');

cron.schedule('* * * Jan,Sep Sun', () => {
  console.log('running on Sundays of January and September');
});

Cron methods

Schedule

Schedules given task to be executed whenever the cron expression ticks.

Arguments:

  • expression string: Cron expression
  • function Function: Task to be executed
  • options Object: Optional configuration for job scheduling.

Options

  • scheduled: A boolean to set if the created task is scheduled. Default true;
  • timezone: The timezone that is used for job scheduling. See moment-timezone for valid values.

Example:

 var cron = require('node-cron');

 cron.schedule('0 1 * * *', () => {
   console.log('Running a job at 01:00 at America/Sao_Paulo timezone');
 }, {
   scheduled: true,
   timezone: "America/Sao_Paulo"
 });

ScheduledTask methods

Start

Starts the scheduled task.

var cron = require('node-cron');

var task = cron.schedule('* * * * *', () =>  {
  console.log('stopped task');
}, {
  scheduled: false
});

task.start();

Stop

The task won't be executed unless re-started.

var cron = require('node-cron');

var task = cron.schedule('* * * * *', () =>  {
  console.log('will execute every minute until stopped');
});

task.stop();

Destroy

The task will be stopped and completely destroyed.

var cron = require('node-cron');

var task = cron.schedule('* * * * *', () =>  {
  console.log('will not execute anymore, nor be able to restart');
});

task.destroy();

Validate

Validate that the given string is a valid cron expression.

var cron = require('node-cron');

var valid = cron.validate('59 * * * *');
var invalid = cron.validate('60 * * * *');

Issues

Feel free to submit issues and enhancement requests here.

Contributing

In general, we follow the "fork-and-pull" Git workflow.

  • Fork the repo on GitHub;
  • Commit changes to a branch in your fork;
  • Pull request "upstream" with your changes;

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Please do not contribute code you did not write yourself, unless you are certain you have the legal ability to do so. Also ensure all contributed code can be distributed under the ISC License.

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

node-cron is under ISC License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].