1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 08:22:35 +01:00
Sonarr/NzbDrone.Core/Jobs/JobRepository.cs

48 lines
1.3 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore;
2013-03-05 06:37:33 +01:00
namespace NzbDrone.Core.Jobs
{
public interface IScheduledTaskRepository : IBasicRepository<ScheduledTask>
{
IList<ScheduledTask> GetPendingJobs();
ScheduledTask GetDefinition(Type type);
2013-05-11 01:53:50 +02:00
void SetLastExecutionTime(int id, DateTime executionTime);
}
public class ScheduledTaskRepository : BasicRepository<ScheduledTask>, IScheduledTaskRepository
{
public ScheduledTaskRepository(IDatabase database, IMessageAggregator messageAggregator)
2013-05-05 23:24:33 +02:00
: base(database, messageAggregator)
{
}
public ScheduledTask GetDefinition(Type type)
{
2013-05-11 01:53:50 +02:00
return Query.Single(c => c.TypeName == type.FullName);
}
public IList<ScheduledTask> GetPendingJobs()
{
2013-05-07 02:39:33 +02:00
return Query.Where(c => c.Interval != 0).ToList().Where(c => c.LastExecution < DateTime.Now.AddMinutes(-c.Interval)).ToList();
}
2013-05-11 01:53:50 +02:00
public void SetLastExecutionTime(int id, DateTime executionTime)
{
var task = new ScheduledTask
{
Id = id,
LastExecution = executionTime
};
SetFields(task, scheduledTask => scheduledTask.LastExecution);
}
}
2013-03-25 04:51:32 +01:00
}