A simple module to set and clear timers using Redis for persistence
The timer object requires tasks to be defined during initialization. These tasks are then matched by name during job execution regardless of which node executes the job. An outline of the full config is below:
var Timer = require('node-distributed-timer');
var Timer = new Timer({
connection: {
host: '127.0.0.1',
port: 6379
}
prefix: 'timer',
ttl: 2000,
tasks: {},
logger: logger
});
Creates a new timer instance. All option keys are optional.
options.connection
: Connection config is passed straight into ioredis, full options at https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-optionsoptions.prefix
: (default: timer) Redis key prefixoptions.ttl
: (default: 2000) Job execution timeout (milliseconds) before releasing the Redis lockoptions.tasks
: Map of task/function pairs used for job execution (see demo.js for an example)options.logger
: Logger for internal logging
Schedules a new job.
task
: Task to run on completion, must exist withinoptions.tasks
id
: ID of the job, will be passed into the associated task method as the only parametertimeout
: Time in milliseconds before the job will execute
Clears an existing task.
task
: Task of the scheduled jobid
: ID of the scheduled job