mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-10-02 08:47:59 +02:00
New: Store Task StartTime, Show Duration in UI
This commit is contained in:
14
src/NzbDrone.Core/Datastore/Migration/163_task_duration.cs
Normal file
14
src/NzbDrone.Core/Datastore/Migration/163_task_duration.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(163)]
|
||||
public class task_duration : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("ScheduledTasks").AddColumn("LastStartTime").AsDateTime().Nullable();
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,5 +8,6 @@ namespace NzbDrone.Core.Jobs
|
||||
public string TypeName { get; set; }
|
||||
public int Interval { get; set; }
|
||||
public DateTime LastExecution { get; set; }
|
||||
public DateTime LastStartTime { get; set; }
|
||||
}
|
||||
}
|
@@ -9,7 +9,7 @@ namespace NzbDrone.Core.Jobs
|
||||
public interface IScheduledTaskRepository : IBasicRepository<ScheduledTask>
|
||||
{
|
||||
ScheduledTask GetDefinition(Type type);
|
||||
void SetLastExecutionTime(int id, DateTime executionTime);
|
||||
void SetLastExecutionTime(int id, DateTime executionTime, DateTime startTime);
|
||||
}
|
||||
|
||||
public class ScheduledTaskRepository : BasicRepository<ScheduledTask>, IScheduledTaskRepository
|
||||
@@ -25,15 +25,16 @@ namespace NzbDrone.Core.Jobs
|
||||
return Query(x => x.TypeName == type.FullName).Single();
|
||||
}
|
||||
|
||||
public void SetLastExecutionTime(int id, DateTime executionTime)
|
||||
public void SetLastExecutionTime(int id, DateTime executionTime, DateTime startTime)
|
||||
{
|
||||
var task = new ScheduledTask
|
||||
{
|
||||
Id = id,
|
||||
LastExecution = executionTime
|
||||
LastExecution = executionTime,
|
||||
LastStartTime = startTime
|
||||
};
|
||||
|
||||
SetFields(task, scheduledTask => scheduledTask.LastExecution);
|
||||
SetFields(task, scheduledTask => scheduledTask.LastExecution, scheduledTask => scheduledTask.LastStartTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ namespace NzbDrone.Core.Jobs
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
_commandQueueManager.Push(task.TypeName, task.LastExecution, CommandPriority.Low, CommandTrigger.Scheduled);
|
||||
_commandQueueManager.Push(task.TypeName, task.LastExecution, task.LastStartTime, CommandPriority.Low, CommandTrigger.Scheduled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -181,7 +181,7 @@ namespace NzbDrone.Core.Jobs
|
||||
if (scheduledTask != null && message.Command.Body.UpdateScheduledTask)
|
||||
{
|
||||
_logger.Trace("Updating last run time for: {0}", scheduledTask.TypeName);
|
||||
_scheduledTaskRepository.SetLastExecutionTime(scheduledTask.Id, DateTime.UtcNow);
|
||||
_scheduledTaskRepository.SetLastExecutionTime(scheduledTask.Id, DateTime.UtcNow, message.Command.StartedAt.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,6 +26,7 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||
|
||||
public string Name { get; private set; }
|
||||
public DateTime? LastExecutionTime { get; set; }
|
||||
public DateTime? LastStartTime { get; set; }
|
||||
public CommandTrigger Trigger { get; set; }
|
||||
public bool SuppressMessages { get; set; }
|
||||
|
||||
|
@@ -17,7 +17,7 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||
{
|
||||
List<CommandModel> PushMany<TCommand>(List<TCommand> commands) where TCommand : Command;
|
||||
CommandModel Push<TCommand>(TCommand command, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified) where TCommand : Command;
|
||||
CommandModel Push(string commandName, DateTime? lastExecutionTime, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified);
|
||||
CommandModel Push(string commandName, DateTime? lastExecutionTime, DateTime? lastStartTime, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified);
|
||||
IEnumerable<CommandModel> Queue(CancellationToken cancellationToken);
|
||||
List<CommandModel> All();
|
||||
CommandModel Get(int id);
|
||||
@@ -124,10 +124,11 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||
return commandModel;
|
||||
}
|
||||
|
||||
public CommandModel Push(string commandName, DateTime? lastExecutionTime, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified)
|
||||
public CommandModel Push(string commandName, DateTime? lastExecutionTime, DateTime? lastStartTime, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified)
|
||||
{
|
||||
dynamic command = GetCommand(commandName);
|
||||
command.LastExecutionTime = lastExecutionTime;
|
||||
command.LastStartTime = lastStartTime;
|
||||
command.Trigger = trigger;
|
||||
|
||||
return Push(command, priority, trigger);
|
||||
|
@@ -54,6 +54,7 @@ namespace Radarr.Api.V3.System.Tasks
|
||||
TaskName = taskName,
|
||||
Interval = scheduledTask.Interval,
|
||||
LastExecution = scheduledTask.LastExecution,
|
||||
LastStartTime = scheduledTask.LastStartTime,
|
||||
NextExecution = scheduledTask.LastExecution.AddMinutes(scheduledTask.Interval)
|
||||
};
|
||||
}
|
||||
|
@@ -9,6 +9,9 @@ namespace Radarr.Api.V3.System.Tasks
|
||||
public string TaskName { get; set; }
|
||||
public int Interval { get; set; }
|
||||
public DateTime LastExecution { get; set; }
|
||||
public DateTime LastStartTime { get; set; }
|
||||
public DateTime NextExecution { get; set; }
|
||||
|
||||
public TimeSpan LastDuration => LastExecution - LastStartTime;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user