1.2.3 • Published 1 year ago

scheduler4js v1.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Scheduler4js

Scheduler4js is a library for scheduling tasks in Node.JS. This library makes easier to dynamically create cron jobs running on sql database from client side.

Featurescheduler4js
BackendPostgresql/Mssql
Priorities
Concurrency
Global events
Atomic ops
Persistence
Supports long running jobs
Supports logging
Supports group jobs
Optimized forJobs

Installation

npm i scheduler4js

Usage:

This library provides a schedule class that accepts a task function and a config representing when the task should be run.

Create db connection and library config to create instance of the library:

TS

import { Scheduler, Frequency, Timezone, CronUtil } from "scheduler4js";

JS

const { Scheduler, Frequency, Timezone, CronUtil } = require("scheduler4js");
async function example() {
  const dbConfig = {
    port: 5432,
    host: "localhost",
    username: "postgres",
    password: "password",
    dialect: "postgres",
    database: "scheduler4js",
    logging: false,
  };

  const config = {
    frequency: Frequency.ONCE_IN_HALF_MINUTE,
    lockLifetime: 6 * 1000,
    type: "x",
    kick: true,
  };

  const scheduler = await Scheduler.init({ dbConfig, config });

  scheduler.enqueueJob({
    name: "example",
    concurrency: 1,
    type: "x",
    timezone: Timezone.ASIA_DUBAI,
    cron: CronUtil.EVERY_X_MINUTE(1),
    lockLimit: 1,
    saveLog: false,
    priority: 0,
    fn: () => {
      console.log(`Job run at the time of ${new Date()}`);
    },
  });

  scheduler.on("begin", (job) => {
    console.log("begin", job);
  });

  scheduler.on("completed", (job) => {
    console.log("completed", job);
  });

  scheduler.on("fail", (err, job) => {
    console.log("fail", err, job);
  });
}

example();

API

Schedules a task to repeat at the specified date.

  • name: The name of the job
  • concurrency: The concurrency of the job
  • type: The type of the job which shows which executor should execute the given job
  • lockLimit: It shows the number of lock limit
  • fn: A function to run when the scheduled time arrives.
  • cron: It's cron expression representing the time to run the task again and again.
  • saveLog: It saves the result of the given jobs when they run
  • priority: Reorder jobs according to the given priority
  • frequency: It specifies the frequency which master cron job repeats in a minute
  • lockLifetime: It shows the lock life time of the jobs in ms
  • kick: To kick jobs to run

License

MIT

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.56

1 year ago

1.0.55

1 year ago

1.0.54

1 year ago

1.0.53

1 year ago

1.0.52

1 year ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.49

1 year ago

1.0.48

1 year ago

1.0.47

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.40

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago