Show duration of previous task run in admin panel.

See: https://github.com/freifunkhamburg/ffffng/issues/29
This commit is contained in:
baldo 2017-05-13 12:08:16 +02:00
parent 3ad8eeffa2
commit 05c6cdafb7
3 changed files with 12 additions and 2 deletions

View file

@ -23,6 +23,10 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
return unix ? moment.unix(unix).fromNow() : 'N/A'; return unix ? moment.unix(unix).fromNow() : 'N/A';
} }
function formatDuration(duration) {
return typeof duration === 'number' ? moment.duration(duration).humanize() : 'N/A';
}
function nodeConstraint(field) { function nodeConstraint(field) {
var constraint = Constraints.node[field]; var constraint = Constraints.node[field];
var result = { var result = {
@ -351,7 +355,8 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
nga.field('schedule').cssClasses(taskClasses('schedule')), nga.field('schedule').cssClasses(taskClasses('schedule')),
nga.field('state').cssClasses(taskClasses('state')), nga.field('state').cssClasses(taskClasses('state')),
nga.field('runningSince').map(formatMoment).cssClasses(taskClasses('runningSince')), nga.field('runningSince').map(formatMoment).cssClasses(taskClasses('runningSince')),
nga.field('lastRunStarted').map(formatMoment).cssClasses(taskClasses('lastRunStarted')) nga.field('lastRunStarted').map(formatMoment).cssClasses(taskClasses('lastRunStarted')),
nga.field('lastRunDuration').map(formatDuration).cssClasses(taskClasses('lastRunDuration'))
]) ])
.filters([ .filters([
nga.field('q') nga.field('q')

View file

@ -38,6 +38,7 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
job: job, job: job,
runningSince: false, runningSince: false,
lastRunStarted: false, lastRunStarted: false,
lastRunDuration: null,
state: 'idle', state: 'idle',
enabled: true enabled: true
}; };
@ -54,8 +55,11 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
job.run(function () { job.run(function () {
var now = moment(); var now = moment();
Logger.tag('jobs').profile('[%sms]\t%s', now.diff(task.runningSince), task.name); var duration = now.diff(task.runningSince);
Logger.tag('jobs').profile('[%sms]\t%s', duration, task.name);
task.runningSince = false; task.runningSince = false;
task.lastRunDuration = duration;
task.state = 'idle'; task.state = 'idle';
}); });
}; };

View file

@ -19,6 +19,7 @@ angular.module('ffffng').factory('TaskResource', function (
schedule: task.schedule, schedule: task.schedule,
runningSince: task.runningSince && task.runningSince.unix(), runningSince: task.runningSince && task.runningSince.unix(),
lastRunStarted: task.lastRunStarted && task.lastRunStarted.unix(), lastRunStarted: task.lastRunStarted && task.lastRunStarted.unix(),
lastRunDuration: task.lastRunDuration || undefined,
state: task.state, state: task.state,
enabled: task.enabled enabled: task.enabled
}; };