UNPKG

spacejam-updated

Version:

Run your meteor package tinytests and mocha tests from the command line with phantomjs.

123 lines (108 loc) 4.12 kB
// Generated by CoffeeScript 1.11.1 (function() { var EventEmitter, MeteorMongodb, expect, ps, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; expect = require('chai').expect; EventEmitter = require('events').EventEmitter; ps = require('psext'); MeteorMongodb = (function(superClass) { extend(MeteorMongodb, superClass); MeteorMongodb.prototype.mongodChilds = []; MeteorMongodb.prototype.killed = false; function MeteorMongodb(meteorPid) { this.meteorPid = meteorPid; log.debug("MeteorMongodb.constructor()", arguments); process.on('exit', (function(_this) { return function(code) { log.debug("MeteorMongodb.process.on 'exit': code=" + code); return _this.kill(); }; })(this)); this.findAllChildren(); } MeteorMongodb.prototype.hasMongodb = function() { log.debug("MeteorMongodb.hasMongodb()"); return this.mongodChilds.length > 0; }; MeteorMongodb.prototype.findAllChildren = function() { log.debug("MeteorMongodb.findAllChildren()", arguments); log.debug("@meteorPid", this.meteorPid); return ps.lookup({ command: 'mongod', psargs: '-l', ppid: this.meteorPid }, (function(_this) { return function(err, resultList) { _this.mongodChilds = resultList; if (err) { return log.warn("spacjam: Warning: Couldn't find any mongod children:\n", err); } else if (resultList.length > 1) { return log.warn("spacjam: Warning: Found more than one mongod child:\n", resultList); } else { return log.debug("Found meteor mongod child with pid: ", resultList[0].pid); } }; })(this)); }; MeteorMongodb.prototype.kill = function() { var attempts, interval, onInterval; log.debug("MeteorMongodb.kill() killed=", this.killed); if (this.killed) { return; } this.killed = true; attempts = 1; interval = null; onInterval = (function(_this) { return function() { var allDead, e, i, j, len, len1, mongod, ref, ref1, signal; if (attempts <= 40) { signal = 0; if (attempts === 1) { signal = "SIGTERM"; } else if (attempts === 20) { signal = "SIGKILL"; } try { ref = _this.mongodChilds; for (i = 0, len = ref.length; i < len; i++) { mongod = ref[i]; if (mongod.dead == null) { try { process.kill(mongod.pid, signal); } catch (error) { e = error; mongod.dead = true; } } } allDead = true; ref1 = _this.mongodChilds; for (j = 0, len1 = ref1.length; j < len1; j++) { mongod = ref1[j]; if (mongod.dead == null) { allDead = false; return; } } if (allDead) { clearInterval(interval); _this.emit("kill-done", null, _this.mongodChilds); } } catch (error) {} return attempts++; } else { clearInterval(interval); log.error("spacejam: Error: Unable to kill all mongodb children, even after 40 attempts"); return _this.emit("kill-done", new Error("Unable to kill all mongodb children, even after 40 attempts"), _this.mongodChilds); } }; })(this); onInterval(); return interval = setInterval(onInterval, 100); }; return MeteorMongodb; })(EventEmitter); module.exports = MeteorMongodb; }).call(this);