organic-worker-interval
v1.0.0
Published
Abstract Organelle providing interval based function execution
Downloads
364
Readme
organic-worker-interval
Abstract Organelle providing interval based function execution with the followup properties:
- executions will be skipped in case of overlapping between them
- executions are setInterval based in the current process
dna
{
log: Boolean,
intervalMiliseconds: Number,
startOn: String,
disposeOn: String defaults to "kill",
startOnInitialization: Boolean
}
usage
- create your organelle
myWorker.js
- implement
myWorker.js
:
const IntervalWorker = require('organic-worker-interval')
module.exports = class extends IntervalWorker {
async execute () {
console.log('running') // TODO add your cron execute logic
}
}
- use your organelle within a cell or standalone:
let Plasma = require('organic-plasma')
let MyWorker = require('./myWorker')
let plasma = new Plasma()
let worker = new MyWorker(plasma, {
log: true,
intervalMiliseconds: 1000 // every second
})
worker.start()
plasma.on('some-chemical', () => {
worker.dispose()
})