0.4.8 • Published 11 months ago

@knowark/schedularkjs v0.4.8

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Schedulark

Job Scheduling Library

Usage

First, you should define your jobs so that they can be registered, referenced and dispatched by your application. A Job is an object with an execute(context) method which holds the information required by the scheduler to enqueue and process it.

import { Job } from '@knowark/schedulark/lib/index.js'

class MaintenanceJob extends Job {
  async execute(self, context) {
    const number = context.number || 1000
    let [first, second] = [0, 1]
    while (first < number) {
      first = second
      second = first + second
    }

    return { data: first }
  }
}

Then you can create an Scheduler instance to control the arrangement and processing of its registered jobs.

import { Scheduler } from '@knowark/schedulark/lib/index.js'

const scheduler = new Scheduler()
scheduler.register(MaintenanceJob)

Finally, you might schedule (using cron expressions) one of the jobs you have previously registered so that it can be enqueued for execution.

scheduler.schedule('MaintenanceJob', {n: 777}, '0 0 * * *')

Summing up, the complete program using Schedulark would look like:

import { Job, Scheduler } from '@knowark/schedulark/lib/index.js'

class MaintenanceJob extends Job {
  async execute(context) {
    const number = context.number || 1000
    let [first, second] = 0, 1
    while (first < number) {
      first = second
      second = first + second
    }

    return { data: first }
  }
}

function main () {
  const scheduler = new Scheduler()
  scheduler.register(MaintenanceJob)

  scheduler.schedule('MaintenanceJob', {number: 765}, '0 0 * * *')
  scheduler.start()
}

main()
0.4.8

11 months ago

0.4.7

11 months ago

0.4.6

12 months ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.3.2

2 years ago

0.3.3

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago