lite-cron
v1.1.0
Published
Simple, lightweight, and dependency-free CRON library for TypeScript.
Downloads
5
Maintainers
Readme
Lite-CRON
Simple, lightweight, and dependency-free CRON library for TypeScript.
Packaged size: 2.78 kB
| Gzipped size: 1.02 kB
Installation
pnpm install lite-cron
Supported formats
.---------------- secondes (0 - 59)
| .------------- minute (0 - 59)
| | .---------- hour (0 - 23)
| | | .------- day of month (1 - 31)
| | | | .---- month (1 - 12)
| | | | | .- day of week (0 - 6) (Sunday=0)
* * * * * *
*
any value*/n
every n valuesn/m
every m values starting at nn
specific valuen-m
range of valuesn,m
list of values
Every missing value is considered as 0
.
Example
0 0 * * * *
every hour* * * *
every hour*/6 * * *
every 6 hours2/6 * * *
every 6 hours starting at 2pm6 * * *
every day at 6am6-8 * * *
every day at 6am, 7am and 8am6,8 * * *
every day at 6am and 8am
Usage
Launch a job
import { Cron } from "lite-cron";
const cron = new Cron({
time: "0 0 */6 * * *",
job: () => {
console.log("Every 6 hours");
}
});
import { Cron } from "lite-cron";
const cron = new Cron({
time: "0 0 */6 * * *",
job: async () => {
await myExpensiveJob();
}
});
Stop a job
cron.stop();