Skip to content

Commit

Permalink
adds PateroHeartBeat.
Browse files Browse the repository at this point in the history
  • Loading branch information
pardo-bsso committed Mar 7, 2014
1 parent 2f214a1 commit cee74e1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions heartbeats/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var _ = require('underscore')
, Backbone = require('backbone')
, App = require('../models/App.js')
, utils = require('../utils')
;

var heartbeats = exports = module.exports;

heartbeats.PateroHeartBeat = function(timeout) {
var self = this;
_.extend(self, Backbone.Events);

var timeout = timeout || 1000;
var heartbeat = new utils.heartbeats.HeartBeat(timeout);
self.heartbeat = heartbeat;

var pateroStatus = new App.TranscodeStatus();
heartbeat.on('down', function() {
self.trigger('down');
});

heartbeat.on('down:tick', function() {
pateroStatus.set('running', false);
pateroStatus.save();
});

heartbeat.on('up', function() {
self.trigger('up');
});

pateroStatus.on('backend', function() {
if (pateroStatus.get('running')) {
heartbeat.beat();
}
});
};

0 comments on commit cee74e1

Please sign in to comment.