expressweb-scheduler

1.0.7 • Public • Published

Setup

ExpressWebJs Scheduler

The software utility cron also known as cron job is a time-based job scheduler in computer operating systems. Users that set up and maintain software environments use cron to schedule jobs to run periodically at fixed times, dates, or intervals. ExpressWebJs Scheduler makes that really easy to achieve.

Getting started

npm install --save expressweb-scheduler

import expressweb-scheduler and schedule a task


  const scheduler = require("expressweb-scheduler");

  scheduler.command('sendNewsletter').everySecond().run();

You can also run a closure function using the call method

  scheduler.call(()=>{
    console.log('this is a closure that is been run every seconds')
  }).everySecond().run();


You can also use the cron method:


  const scheduler = require("expressweb-scheduler");

  scheduler.command('sendNewsletter').cron('* * * * * *').run();


Allowed fields in cron method

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

Allowed Values And Schedule Frequency Options

We've already seen a few examples of how you may configure a task to run at specified intervals. However, there are many more task schedule frequencies that you may assign to a task:


field field
->second 0-59
->minute 0-59
->hour 0-23
->day of month 1-12 (or names)
->month 1-12 (or names)
->day of week 0-7 (or names, 0 or 7 are sunday)
Method Description
->cron('* * * * *'); Run the task on a custom cron schedule
->everyMinute(); Run the task every minute
->everyTwoMinutes(); Run the task every two minutes
->everyThreeMinutes(); Run the task every three minutes
->everyFourMinutes(); Run the task every four minutes
->everyFiveMinutes(); Run the task every five minutes
->everyTenMinutes(); Run the task every ten minutes
->everyFifteenMinutes(); Run the task every fifteen minutes
->everyThirtyMinutes(); Run the task every thirty minutes
->hourly(); Run the task every hour
->hourlyAt(17); Run the task every hour at 17 minutes past the hour
->everyTwoHours(); Run the task every two hours
->everyThreeHours(); Run the task every three hours
->everyFourHours(); Run the task every four hours
->everySixHours(); Run the task every six hours
->daily(); Run the task every day at midnight
->dailyAt('13:00'); Run the task every day at 13:00
->twiceDaily(1, 13); Run the task daily at 1:00 & 13:00
->weekly(); Run the task every Sunday at 00:00
->weeklyOn(1, '8:00'); Run the task every week on Monday at 8:00
->monthly(); Run the task on the first day of every month at 00:00
->monthlyOn(4, '15:00'); Run the task every month on the 4th at 15:00
->twiceMonthly(1, 16, '13:00'); Run the task monthly on the 1st and 16th at 13:00
->lastDayOfMonth('15:00'); Run the task on the last day of the month at 15:00
->quarterly(); Run the task on the first day of every quarter at 00:00
->yearly(); Run the task on the first day of every year at 00:00
->yearlyOn(6, 1, '17:00'); Run the task every year on June 1st at 17:00
->timezone('America/New_York'); Set the timezone for the task

Visit ExpressWebJs Documentation site for more info.

ExpressWebJs is a Node FrameWork with expressive and organised syntax that runs on all major operating systems. It provides the starting point for creating your node project, allowing you to focus more on developing your amazing solution.

Package Sidebar

Install

npm i expressweb-scheduler

Weekly Downloads

0

Version

1.0.7

License

ISC

Unpacked Size

14 kB

Total Files

3

Last publish

Collaborators

  • alexigbokwe