1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

using Scheduler.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Scheduler.Backgrounding
{
public class BGTaskInfo : IDeepCloneable<BGTaskInfo>
{
public int IntervalID { get; }
public Guid TaskBackgrounderID { get; }
public DateTime StartedAt { get; }
public DateTime? EndedAt { get; private set; }
public bool HasFinished { get; private set; }
public TimeSpan Duration => HasFinished && EndedAt.HasValue
? (EndedAt - StartedAt).Value
: TimeSpan.Zero;
public BGTaskInfo(int intervalID, Guid taskBackgrounderID, DateTime startedAt)
{
IntervalID = intervalID;
TaskBackgrounderID = taskBackgrounderID;
StartedAt = startedAt;
}
public void Finish(DateTime endedAt)
{
EndedAt = endedAt;
HasFinished = true;
}
public BGTaskInfo Clone() => new(IntervalID, TaskBackgrounderID, StartedAt)
{
EndedAt = EndedAt,
HasFinished = HasFinished
};
}
}