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

Remove dependency on timespan #1014

Merged
merged 2 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"prototypejs": false,
"mootools": false,
"dojo": false,
"esversion": 5,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we may want to bump it, better to be explicit. Almost used template literals in this PR :)


"devel": true,

Expand Down Expand Up @@ -50,4 +51,4 @@
"trailing": true,
"white": false,
"indent": 2
}
}
16 changes: 14 additions & 2 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var fs = require('fs'),
cliff = require('cliff'),
nconf = require('nconf'),
nssocket = require('nssocket'),
timespan = require('timespan'),
utile = require('utile'),
winston = require('winston'),
mkdirp = utile.mkdirp,
Expand Down Expand Up @@ -1037,7 +1036,20 @@ forever.columns = {
uptime: {
color: 'yellow',
get: function (proc) {
return proc.running ? timespan.fromDates(new Date(proc.ctime), new Date()).toString().yellow : "STOPPED".red;
if (!proc.running) {
return "STOPPED".red;
}

var delta = (new Date().getTime() - proc.ctime) / 1000;
var days = Math.floor(delta / 86400);
delta -= days * 86400;
var hours = Math.floor(delta / 3600) % 24;
delta -= hours * 3600;
var minutes = Math.floor(delta / 60) % 60;
delta -= minutes * 60;
var seconds = delta % 60;

return (days+':'+hours+':'+minutes+':'+seconds).yellow;
}
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"path-is-absolute": "~1.0.0",
"prettyjson": "^1.1.2",
"shush": "^1.0.0",
"timespan": "~2.3.0",
"utile": "~0.2.1",
"winston": "~0.8.1"
},
"devDependencies": {
"broadway": "~0.3.6",
"eventemitter2": "0.4.x",
"moment": "^2.23.0",
"request": "2.x.x",
"vows": "0.7.x"
},
Expand Down
28 changes: 28 additions & 0 deletions test/core/uptime-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var assert = require('assert'),
vows = require('vows'),
moment = require('moment'),
forever = require('../../lib/forever');

vows.describe('forever/core/uptime').addBatch({
"When using forever" : {
"calculates uptime" : {
"for not running process correctly": function (err, procs) {
assert.equal(forever.columns.uptime.get({}), 'STOPPED'.red);
},
"calculates uptime for running process correctly": function (err, procs) {
var launchTime = moment.utc()
.subtract(4000, 'days')
.subtract(6, 'hours')
.subtract(8, 'minutes')
.subtract(25, 'seconds');

var timeWithoutMsecs = forever.columns.uptime.get({
running: true,
ctime: launchTime.toDate().getTime()
}).strip.split('.')[0];

assert.equal(timeWithoutMsecs, '4000:6:8:25');
}
}
}
}).export(module);