UNPKG

@mihon/spacejam

Version:

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

123 lines (108 loc) 4.15 kB
// Generated by CoffeeScript 1.8.0 (function() { var EventEmitter, MeteorMongodb, expect, ps, __hasProp = {}.hasOwnProperty, __extends = 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; }; expect = require('chai').expect; EventEmitter = require('events').EventEmitter; ps = require('psext'); MeteorMongodb = (function(_super) { __extends(MeteorMongodb, _super); 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, mongod, signal, _i, _j, _len, _len1, _ref, _ref1; 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);