Coder Social home page Coder Social logo

rbrahul / deno_cron Goto Github PK

View Code? Open in Web Editor NEW
99.0 2.0 2.0 85 KB

A cron Job scheduler for Deno that allows you to write human readable cron syntax with tons of flexibility

License: MIT License

TypeScript 100.00%
deno cron cronjob crontab scheduler

deno_cron's Introduction

deno_cron

A smart cron Job scheduler library for Deno. It allows you to write human readable cron syntax with tons of flexibility. Writing cron syntax and operation can be very tadious for many developers. This extensions provides very developer friendly api to write any job scheduler's cron syntax you need.

Deno Cron

Installation:

import {cron, daily, monthly, weekly} from 'https://deno.land/x/deno_cron/cron.ts';

daily(() => {
    backupDatabase();
});


weekly(() => {
    sendNewsLetter();
});

// Runs the Job on 5th day of every month
monthly(() => {
    sendUsageReport();
}, 5);

// Run Job in every 30 minutes
cron('1 */30 * * * *', () => {
    checkStock();
});

Writing CRON Job:

Here is the CRON style syntax to write tons of custom cron schedule.

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sunday)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59) - [Optional 01 as default]

Syntax Table:

Field Required Allowed Values Allowed Special Character
Seconds No 0-59 / - , *
Minute Yes 0-59 / - , *
Hour Yes 0-23 / - , *
Day of Month Yes 1-31 / - , *
Month Yes 1-12 / - , *
Day of Week Yes 0-6 (0 is Sunday) / - , *

Example:

// This Job will be executed 1st day of every month at mid-night.
cron('1 0 0 1 */1 *', () => {
    sendMails();
});

// Job will be executed for 1st to 7th day of every month on 3rd, 6th and 9th hour and every 30 minutes if it's monday

cron('1 */30 3,6,9 1-7 */1 1', () => {
    sendMails();
});

API:

Function Parameter
cron(schedule, job) schedule: string required - cron syntax, job: func required - function to be executed
everyMinute(job) job: func required - function to be executed
every15Minute(job) job: func required - function to be executed
hourly(job) job: func required - function to be executed
daily(job) job: func required - function to be executed
weekly(job, weekDay?) job: func required - function to be executed, weekDay: string or number {optional} - Represents weekday; 0-6, (0 represents Sunday) default: 1
biweekly(job) job: func required - function to be executed
monthly(job, dayOfMonth) job: func required - function to be executed, dayOfMonth: string or number {optional} - 1-31, default: 1
yearly(job) job: func required - function to be executed
stop() - Stop all the scheduled job
start() - If schedulers have been stopped before then starts again

Change Log:

  • Initial version released on - 23-05-2020

Contributors:

Rahul Baruri

License

Distributed under the MIT License.

https://github.com/rbrahul/deno_cron/blob/master/README.md

Developed with ❤️ for Deno community

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.