npm

expressweb-scheduler-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published


ExpressWebJs Scheduler Typescript Version

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

  • First install expressweb-scheduler-ts
    npm install --save expressweb-scheduler-ts
  • Import Scheduler
import { Schedule } from "expressweb-scheduler-ts";
  • Schedule a command
Schedule.command("sendNewsletter").everySecond().run();
  • You can also run a closure function using the call method
Schedule.call(() => {
  console.log("this is a closure that is been run every seconds");
})
  .everySecond()
  .run();
  • You can also use the cron method:
Schedule.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 Value
->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 powerful and flexible Node FrameWork for building efficient and scalable backend services for modern applications. It is designed to be easy to use and flexible, allowing you to build a wide range of backend services.

It includes support for enterprise-level features such as building multi-tenant systems, distributed systems, multi-threading, real-time events, queues, dependency injection, testing, and more. With ExpressWebJs, you can easily build efficient and reliable backend services that can handle a large volume of traffic and data.

Package Sidebar

Install

npm i expressweb-scheduler-ts

Weekly Downloads

3

Version

1.0.6

License

ISC

Unpacked Size

20.8 kB

Total Files

6

Last publish

Collaborators

  • alexigbokwe