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';
}
function formatDuration(duration) {
return typeof duration === 'number' ? moment.duration(duration).humanize() : 'N/A';
}
function nodeConstraint(field) {
var constraint = Constraints.node[field];
var result = {
@ -351,7 +355,8 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
nga.field('schedule').cssClasses(taskClasses('schedule')),
nga.field('state').cssClasses(taskClasses('state')),
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([
nga.field('q')

View file

@ -38,6 +38,7 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
job: job,
runningSince: false,
lastRunStarted: false,
lastRunDuration: null,
state: 'idle',
enabled: true
};
@ -54,8 +55,11 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
job.run(function () {
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.lastRunDuration = duration;
task.state = 'idle';
});
};

View file

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