Skip to content

Instantly share code, notes, and snippets.

@zubairov
Created April 8, 2014 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zubairov/10126556 to your computer and use it in GitHub Desktop.
Save zubairov/10126556 to your computer and use it in GitHub Desktop.
{
"title":"Timer",
"description" : "A task that can be scheduled for one-time or repeated execution by a Timer.",
"fields":{
"interval":{
"viewClass":"SelectView",
"label":"Interval",
"required":true,
"model":{
"minute":"Every Minute",
"hour":"Every Hour",
"day":"Every Day"
},
"prompt":"Please select an interval"
}
},
"triggers":{
"timer":{
"title":"Timer",
"main":"./timer.js",
"type": "polling",
"metadata" : {
"out" : {
"type" : "object",
"properties" : {
"fireTime" : {
"type" : "string",
"format" : "date-time",
"required" : true
}
}
}
}
}
}
}
var clock = require('./clock.js');
exports.process = function (msg, conf, next, snapshot) {
var interval = conf.interval,
now = new Date().getTime(),
nextStartTime = snapshot.time || now;
if (nextStartTime <= now) {
this.logger.info("Timer is about to start task execution scheduled for: %s", new Date(nextStartTime));
var nextTime = clock.nextTime(interval);
this.logger.info("Next timer event will be fired shortly after : %s", new Date(nextTime));
var newSnapshot = {
time : nextTime.getTime()
};
var body = {
fireTime : new Date(now)
};
msg.body = body;
next(null, msg, newSnapshot);
} else {
this.logger.debug("It is too early to trigger timer event, next event should be triggered shortly after %s", new Date(nextStartTime));
next();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment