SignalR for tasks, better handling of future/disabled jobs

pull/4/head
Mark McDowall 10 years ago
parent 80ed203258
commit 51b397a00c

@ -2,18 +2,21 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.SignalR;
namespace NzbDrone.Api.System.Tasks
{
public class TaskModule : NzbDroneRestModule<TaskResource>
public class TaskModule : NzbDroneRestModuleWithSignalR<TaskResource, ScheduledTask>, IHandle<CommandExecutedEvent>
{
private readonly ITaskManager _taskManager;
private static readonly Regex NameRegex = new Regex("(?<!^)[A-Z]", RegexOptions.Compiled);
public TaskModule(ITaskManager taskManager)
: base("system/task")
public TaskModule(ITaskManager taskManager, IBroadcastSignalRMessage broadcastSignalRMessage)
: base(broadcastSignalRMessage, "system/task")
{
_taskManager = taskManager;
GetResourceAll = GetAll;
@ -38,5 +41,10 @@ namespace NzbDrone.Api.System.Tasks
NextExecution = scheduledTask.LastExecution.AddMinutes(scheduledTask.Interval)
};
}
public void Handle(CommandExecutedEvent message)
{
BroadcastResourceChange(ModelAction.Sync);
}
}
}

@ -204,3 +204,21 @@ td.delete-episode-file-cell {
.clickable();
}
}
.task-interval-cell, .next-execution-cell {
cursor : default;
}
.task-interval-cell {
width : 150px;
}
.next-execution-cell {
width : 200px;
}
.tasks {
.relative-time-cell {
width : 200px;
}
}

@ -0,0 +1,45 @@
'use strict';
define(
[
'Cells/NzbDroneCell',
'moment',
'Shared/UiSettingsModel'
], function (NzbDroneCell, moment, UiSettings) {
return NzbDroneCell.extend({
className: 'next-execution-cell',
render: function () {
this.$el.empty();
var interval = this.model.get('interval');
var nextExecution = moment(this.model.get('nextExecution'));
if (interval === 0 ) {
this.$el.html('-');
}
else if (moment().isAfter(nextExecution)) {
this.$el.html('now');
}
else {
var result = '<span title="{0}">{1}</span>';
if (UiSettings.get('showRelativeDates')) {
var tooltip = nextExecution.format(UiSettings.longDateTime());
var text = nextExecution.fromNow();
this.$el.html(result.format(tooltip, text));
}
else {
this.$el.html(nextExecution.format(UiSettings.longDateTime()));
}
}
return this;
}
});
});

@ -13,11 +13,15 @@ define(
this.$el.empty();
var interval = this.model.get('interval');
var duration = moment.duration(interval, 'minutes').humanize();
var duration = moment.duration(interval, 'minutes').humanize().replace(/an?(?=\s)/, '1');
this.$el.html(
duration.replace(/an?(?=\s)/, '1')
);
if (interval === 0 ) {
this.$el.html('disabled');
}
else {
this.$el.html(duration);
}
return this;
}

@ -7,8 +7,17 @@ define(
'Cells/RelativeTimeCell',
'System/Task/TaskIntervalCell',
'System/Task/ExecuteTaskCell',
'Shared/LoadingView'
], function (Marionette, Backgrid, BackupCollection, RelativeTimeCell, TaskIntervalCell, ExecuteTaskCell, LoadingView) {
'System/Task/NextExecutionCell',
'Shared/LoadingView',
'Mixins/backbone.signalr.mixin'
], function (Marionette,
Backgrid,
BackupCollection,
RelativeTimeCell,
TaskIntervalCell,
ExecuteTaskCell,
NextExecutionCell,
LoadingView) {
return Marionette.Layout.extend({
template: 'System/Task/TaskLayoutTemplate',
@ -39,7 +48,7 @@ define(
name : 'nextExecution',
label : 'Next Execution',
sortable : true,
cell : RelativeTimeCell
cell : NextExecutionCell
},
{
name : 'this',
@ -53,6 +62,7 @@ define(
this.taskCollection = new BackupCollection();
this.listenTo(this.taskCollection, 'sync', this._showTasks);
this.taskCollection.bindSignalR();
},
onRender: function () {

@ -1,5 +1,5 @@
<div class="row">
<div class="col-md-12">
<div id="x-tasks" class="table-responsive"/>
<div id="x-tasks" class="tasks table-responsive"/>
</div>
</div>

Loading…
Cancel
Save