0.0.14 • Published 1 year ago

work-on-time v0.0.14

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

work-on-time

Simple job scheduler, that reports task status started, failed, completed or stopped.

Installation

npm install work-on-time

Usage

Basic approach is you define a worker. Worker is a object with worker name and handler function that would be run when a task is added for that worker.

Then you add a task for that worker. Task is object with worker name, data to be passed to handler and 'when' parameter when do you want to execute the task.

Here is a simple usage:

// import required classes
const {WorkOnTime, Worker, MongoStore } = require('work-on-time');
// initiate WorkOnTime
const wot = new WorkOnTime({
  mongoUri: uri
});
await wot.init();

await wot.start();

// teaMaker example
const teaMaker = new Worker({
  name: 'teaMaker',
  handler: async (data) => {
    await delay(5 * 1000); // 5 secs
    return Promise.resolve({cups: data.cups});
  }
});

// add event lister on worker
teaMaker.on('complete', (result)=> {
  console.log(`Served ${result.cups} cups of tea.`);
});

wot.addWorker(teaMaker);

// add task
const teaTask = await wot.addTask({
  worker: 'teaMaker',
  when: '0 6 * * *',
  data: {
    cups: 1
  }
});

// add event listener on task
teaTask.on('complete', (result)=> {
  console.log(`Served ${result.cups} cups of tea.`);
});

Demo

There is a simple demo using work-on-time lib. ./demo folder contains demo-server.js a express server that uses express adapter for work-on-time. And there is demo-wot.js file containing many examples of workers and tasks. To run:

npm run demo

This serve on port 3000 (http://127.0.0.1:3000/)

API

TODO

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

1 year ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.2-alpha.9

2 years ago

0.0.3

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.2-alpha.8

2 years ago

0.0.2-alpha.7

2 years ago

0.0.2-alpha.4

2 years ago

0.0.2-alpha.3

2 years ago

0.0.2-alpha.6

2 years ago

0.0.2-alpha.5

2 years ago

0.0.2-alpha.2

2 years ago

0.0.2-alpha.1

2 years ago

0.0.2-alpha.0

2 years ago