0.2.0 • Published 2 years ago

worker-scheduler v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

worker-scheduler

npm Build Status Test Coverage License

Ever wanted to schedule jobs like "this thing should execute every x hours/minutes/seconds"? Then this library is for you! You can even trigger workers manually! Works with native promises, as I don't think you want to do synchronous work in your background workers.

What's a "worker"?

Let me just show you a quick example:

index.js

const Scheduler = require('worker-scheduler');

const myScheduler = new Scheduler();
const worker = new Scheduler.Worker('mycoolworker', require.resolve('./myworker'), 86400 * 1000);

worker.on('finish', (ip) => {
  console.log(ip);
});
worker.on('error', e => console.error(e));

myworker.js

const fetch = require('node-fetch');

// NOTE: This *has* to be an async function (or a Promise-returning function),
//       otherwise the scheduler won't know what to do with it!
module.exports = async (log) => {
  log('I can even log stuff here! Yay!');
  return fetch('https://api.ipify.org').then(res => res.text());
};

This simple example would fetch your public IP address, return it, and console.log it out every day! (Every worker is forked out of the scheduler, so don't worry about hanging your master process!)

0.2.0

2 years ago

0.1.9

2 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

5 years ago

0.1.0

5 years ago