forked from brthor/Gofer.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScheduledTask.cs
50 lines (42 loc) · 1.34 KB
/
ScheduledTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Threading.Tasks;
using Gofer.NET.Utils;
using NCrontab;
using Newtonsoft.Json;
namespace Gofer.NET
{
[JsonObject(MemberSerialization.OptIn)]
public class ScheduledTask
{
public string LockKey => $"{nameof(ScheduledTask)}::{TaskKey}::ScheduleLock";
[JsonProperty]
public string TaskKey { get; private set; }
[JsonProperty]
public long ScheduledUnixTimeMilliseconds { get; private set; }
[JsonProperty]
public TaskInfo TaskInfo { get; private set; }
public ScheduledTask() { }
public ScheduledTask(
TaskInfo taskInfo,
TimeSpan offset,
string taskKey) : this(taskInfo, new DateTimeOffset(DateTime.UtcNow + offset), taskKey)
{
}
public ScheduledTask(
TaskInfo taskInfo,
DateTime scheduledTime,
TaskQueue taskQueue,
string taskKey) : this(taskInfo, new DateTimeOffset(scheduledTime), taskKey)
{
}
public ScheduledTask(
TaskInfo taskInfo,
DateTimeOffset scheduledDateTimeOffset,
string taskKey)
{
TaskKey = taskKey;
TaskInfo = taskInfo;
ScheduledUnixTimeMilliseconds = scheduledDateTimeOffset.ToUnixTimeMilliseconds();
}
}
}