1.0.3 • Published 6 years ago
skedula v1.0.3
⏰ Skedula
Easily (node-cron-based) schedule interval-based processes in Node.js!
Why use Skedula over setInterval?
Skedula uses
node-cronin the backend to schedule tasks when a CRON expression ticks, rather than waiting to execute a function using system time. This improves program efficiency greatly.
⬇ Installation
If you're using npm:
npm install skedulaOr, if you're using yarn:
yarn add skedula💥 Usage
In JavaScript:
const { Skedula } = require('skedula')
// Log every second
const scheduledTask = Skedula.secondInterval(() => {
console.log('This should log every second.')
}, 1)
// Stop in 5 seconds
setTimeout(() => { scheduledTask.stop() }, 5000)In TypeScript:
import { Skedula } from 'skedula'
// Log every second
const scheduledTask = Skedula.secondInterval(() => {
console.log('This should log every second.')
}, 1)
// Stop in 5 seconds
setTimeout(() => { scheduledTask.stop() }, 5000)Documentation
Skedula Functions
secondInterval (returns void)
Run a function every n seconds.
callback((..args:any[])=>void) The function to call.every(number) The interval, in seconds....args(any[]?) The arguments to pass into the function.
minuteInterval (returns void)
Run a function every n minutes.
callback((..args:any[])=>void) The function to call.every(number) The interval, in minutes....args(any[]?) The arguments to pass into the function.
hourInterval (returns void)
Run a function every n hours.
callback((..args:any[])=>void) The function to call.every(number) The interval, in hours....args(any[]?) The arguments to pass into the function.
dailyInterval (returns void)
Run a function every n days.
callback((..args:any[])=>void) The function to call.every(number) The interval, in days....args(any[]?) The arguments to pass into the function.
schedule
Schedule a function called precisely at a certain time, range, or interval.
callback((..args:any[])=>void) The function to call.args(any[], default[]) The arguments to pass into the function.dayOfWeek(DayOfWeekorInterval<Range<DayOfWeek> or DayOfWeek or SkedulaWildcard>orRange<DayOfWeek>orSkedulaWildcard, default*) The day of the week to call the function. Leave undefined or null for every day of the week.month(MonthorInterval<Range<Month> or Month or SkedulaWildcard>orRange<Month>orSkedulaWildcard, default*) The month to call the function. Leave undefined or null for every month of the year.day(DayorInterval<Range<Day> or Day or SkedulaWildcard>orRange<Day>orSkedulaWildcard, default*) The day of the month to call the function. Leave undefined or null for every day of the month.hour(HourorInterval<Range<Hour> or Hour or SkedulaWildcard>orRange<Hour>orSkedulaWildcard, default*) The hour of the day to call the function. Leave undefined or null for every hour of the day.minute(MinuteorInterval<Range<Minute> or Minute or SkedulaWildcard>orRange<Minute>orSkedulaWildcard, default*) The minute of the hour to call the function. Leave undefined or null for every minute of every hour.second(SecondorInterval<Range<Second> or Second or SkedulaWildcard>orRange<Second>orSkedulaWildcard, default*) The second of the minute to call the function. Leave undefined or null for every second of every minute.
Skedula Objects
DayOfMonth
export type DayOfMonth = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31DayOfWeek
export enum DayOfWeek {
SUNDAY = 0,
MONDAY = 1,
TUESDAY = 2,
WEDNESDAY = 3,
THURSDAY = 4,
FRIDAY = 5,
SATURDAY = 6,
}Month
export enum Month {
JANUARY = 0,
FEBRUARY = 1,
MARCH = 2,
APRIL = 3,
MAY = 4,
JUNE = 5,
JULY = 6,
AUGUST = 7,
SEPTEMBER = 8,
OCTOBER = 9,
NOVEMBER = 10,
DECEMBER = 11,
}SkedulaWildcard
type SkedulaWildcard = '*'