SignalR for tasks, better handling of future/disabled jobs

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

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

@ -204,3 +204,21 @@ td.delete-episode-file-cell {
.clickable(); .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(); this.$el.empty();
var interval = this.model.get('interval'); 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( if (interval === 0 ) {
duration.replace(/an?(?=\s)/, '1') this.$el.html('disabled');
); }
else {
this.$el.html(duration);
}
return this; return this;
} }

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

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

Loading…
Cancel
Save