timer-jobs
Create timers that can run often, but not block by long executions. Great for worker-roles and such that have many jobs to do periodically.
Installation
$ npm install timer-jobs
Usage
var TimerJob = ;var someTimer = interval: 5000 {console;;};someTimerstart;
TimerJob Class
constructor (options, callback)
Options:
blocking
:boolean
- This determines if the timer should allow a new callback to be started before one finishes. Defaults totrue
.interval
: Interval time, in milliseconds. Attempts to start the callback at this value.autoStart
:boolean
- No need to calltimer.start()
after creating the timer. Defaults tofalse
.immediate
:boolean
- Iftrue
, calls the callback right when the job starts, doesn't wait forinterval
milliseconds. Defaults tofalse
ignoreErrors
:boolean
- Fftrue
, automatically restarts the job if an error was sent from the callback.
Callback:
The function
to call every interval
milliseconds.
timer.start()
Starts up ye olde job!
timer.stop()
Stop the job! If a callback is in the middle of execution, it does not cancel it. Only when it calls back.
Event: start
{}
Emitted when the timer has successfully started.
Event: stop
{}
Emitted when the timer has successfully stopped.
Event: jobStart
{}
Emitted on every interval, BEFORE the callback function is called
Event: jobStop
{}
Emitted every time the callback calls its done
function. If there is an error - the job HALTS until you start it back up, or if options.ignoreErrors
is true.
err
: Error passed from the callbackargs
: Any additional arguments passed from the callback