Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Crashes Counter & Custom Data Field #15

Merged
merged 2 commits into from
May 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ var Monitor = function(command, opts) {
this.name = opts.name
this.cwd = opts.cwd || '.'
this.env = opts.env || {}
this.data = opts.data || {}
this.uid = opts.uid
this.gid = opts.gid
this.pid = 0
this.crashes = 0
this.stdio = opts.stdio
this.stdout = opts.stdout
this.stderr = opts.stderr
Expand Down Expand Up @@ -125,7 +127,7 @@ Monitor.prototype.start = function() {
child.stdout.on('data', function(data) {
self.emit('stdout', data)
})

if (self.stdout) {
child.stdout.pipe(self.stdout)
}
Expand All @@ -135,7 +137,7 @@ Monitor.prototype.start = function() {
child.stderr.on('data', function(data) {
self.emit('stderr', data)
})

if (self.stderr) {
child.stderr.pipe(self.stderr)
}
Expand Down Expand Up @@ -190,22 +192,27 @@ Monitor.prototype.toJSON = function() {
status: this.status,
started: this.started,
pid: this.pid,
crashes: this.crashes,
command: this.command,
cwd: this.cwd,
env: this.env
env: this.env,
data: this.data
}

if (!doc.id) delete doc.id
if (!doc.pid) delete doc.pid
if (!doc.name) delete doc.name
if (!doc.data) delete doc.data
if (!doc.started) delete doc.started
if (!doc.crashes) delete doc.crashes

return doc
}

Monitor.prototype._crash = function() {
if (this.status !== 'running') return
this.status = 'crashed'
this.crashes = this.crashes++
this.emit('crash')
if (this.status === 'crashed') this._stopped()
}
Expand Down