0.4.1 • Published 6 days ago

@knowark/schedularkjs v0.4.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 days 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.1

6 days ago

0.3.2

6 days ago

0.3.3

6 days ago

0.3.1

17 days ago

0.3.0

20 days ago

0.2.1

12 months ago

0.2.0

1 year ago

0.1.0

2 years ago