UNPKG

el-borracho-stats

Version:

REST and SSE API and worker producing daily and all-time totals for Bull queues

73 lines (63 loc) 2.42 kB
// Generated by IcedCoffeeScript 108.0.11 var ElBorrachoStatsWorker, iced, __iced_k, __iced_k_noop, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; iced = require('iced-runtime'); __iced_k = __iced_k_noop = function() {}; ElBorrachoStatsWorker = (function() { function ElBorrachoStatsWorker(_arg) { var expire, namespace, queuename, redis; namespace = _arg.namespace, this.queue = _arg.queue, this.interval = _arg.interval, expire = _arg.expire; this.stop = __bind(this.stop, this); this.poll = __bind(this.poll, this); this.listen = __bind(this.listen, this); this.Store = require("../models/stats"); redis = this.queue.client; queuename = this.queue.name; this.interval || (this.interval = 5 * 1000); this.store = new this.Store({ redis: redis, namespace: namespace, queuename: queuename, expire: expire }); } ElBorrachoStatsWorker.prototype.listen = function() { var ___iced_passed_deferral, __iced_deferrals, __iced_k; __iced_k = __iced_k_noop; ___iced_passed_deferral = iced.findDeferral(arguments); (function(_this) { return (function(__iced_k) { __iced_deferrals = new iced.Deferrals(__iced_k, { parent: ___iced_passed_deferral, filename: "/home/charles/source/el-borracho-stats/src/controllers/worker.coffee", funcname: "ElBorrachoStatsWorker.listen" }); _this.store.lock(__iced_deferrals.defer({ lineno: 11 })); __iced_deferrals._fulfill(); }); })(this)((function(_this) { return function() { _this.queue.on("completed", _this.store.incrementCompleted); _this.queue.on("failed", _this.store.incrementFailed); return _this.poll(); }; })(this)); }; ElBorrachoStatsWorker.prototype.poll = function() { return this._poller = setInterval(this.store.update, this.interval); }; ElBorrachoStatsWorker.prototype.stop = function(callback) { if (this._poller) { clearInterval(this._poller); delete this._poller; } this.queue.removeListener("completed", this.store.incrementCompleted); this.queue.removeListener("failed", this.store.incrementFailed); return this.store.unlock(callback); }; return ElBorrachoStatsWorker; })(); module.exports = ElBorrachoStatsWorker; //# sourceMappingURL=worker.js.map