Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gagan-bansal/work-on-time
Simple job scheduler for Node.js with persistence store.
https://github.com/gagan-bansal/work-on-time
job-scheduler jobs nodejs scheduler task task-manager task-runner task-scheduler worker
Last synced: about 7 hours ago
JSON representation
Simple job scheduler for Node.js with persistence store.
- Host: GitHub
- URL: https://github.com/gagan-bansal/work-on-time
- Owner: gagan-bansal
- License: mit
- Created: 2021-12-30T10:37:11.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-21T17:34:05.000Z (almost 2 years ago)
- Last Synced: 2024-11-10T21:13:07.685Z (7 days ago)
- Topics: job-scheduler, jobs, nodejs, scheduler, task, task-manager, task-runner, task-scheduler, worker
- Language: JavaScript
- Homepage:
- Size: 4.54 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```js
// 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:
```sh
npm run demo
```This serve on port 3000 (http://127.0.0.1:3000/)
## API
TODO