node.js - Periodically monitor if record is not updated Using Node & Event & setTimeOut -


here scenario :

  1. every 1 checks in every 5 minutes
  2. if 1 misses , should able keep track of it.
  3. if 1 misses n number of times alert should generated.

here have implemented far :

var report = function(attendence) {   this.attendence = attendence;   eventemitter.call(this); };  util.inherits(report, eventemitter);  report.prototype.addapsstatsdata = function() {    var attendencedb = new report(this.attendence);    //promise    var prsave = attendencedb.save();   var self = this;   prsave.then(function(data) {      //emitting event data has been saved      self.emit('attendencerecieved', data.username);      var savetime = date.now();     self.moniterapsstatsdata(data.username, savetime);    }).catch(function(err) {     self.emit('error', err);   }); };  report.prototype.moniterapsstatsdata = function(username, time) {    var cachekey = appconfig.cache_key_usertimeinterval + username;   var prevtimer = memorycache.get(cachekey);    if(!prevtimer)      cleartimeout(prevtimer);    var timer = settimeout(this.monitercallbackafterinterval, (5 * 60000), username, time ,cachekey);    //putting timout in cache later on can clearedout if new attendence comes in    memorycache.set(cachekey, timer);  };  report.prototype.monitercallbackafterinterval = function(username, time ,cachekey) {   //removing cache   memorycache.del(cachekey);    //emitting event next operation can handeld   this.emit('reportnotrecieved'); }; 
  • do think approach ?
  • it hold in production env ?
  • any alternatives settimeout can used here ?

thank much.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -