-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathSchedulerTask.cs
More file actions
71 lines (62 loc) · 2.67 KB
/
Copy pathSchedulerTask.cs
File metadata and controls
71 lines (62 loc) · 2.67 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Arrowgene.Ddon.Shared.Model.Scheduler;
using System;
namespace Arrowgene.Ddon.GameServer.Tasks
{
public abstract class SchedulerTask
{
public TaskType Type { get; }
public ScheduleInterval Interval { get; }
/// <summary>
/// Returns the UTC offset to use when computing the next fire time. Evaluated fresh on
/// every NextTimestamp() call so DST transitions are picked up automatically when a
/// ServerTimeZoneId is configured.
/// </summary>
public TimeSpan Offset => GetOffset();
/// <summary>
/// Delegate that produces the current UTC offset. Set by ScheduleManager using the
/// server's ServerTimeZoneId / ServerUtcOffset settings.
/// </summary>
public Func<TimeSpan> GetOffset { get; set; } = () => TimeSpan.Zero;
/// <param name="interval">Hint for the type of interval this task is expected to occur at.</param>
/// <param name="type">
/// The task type which is stored in the DB and used to resume the scheduler
/// timer when the head server starts.
/// </param>
public SchedulerTask(ScheduleInterval interval, TaskType type)
{
Type = type;
Interval = interval;
}
/// <summary>
/// Runs on the head server. Should deal with things like modifying the database.
/// Should use the RPC manage if it is required to update clients on different channels
/// or send annoucements to players.
/// </summary>
/// <param name="server">The head server object</param>
public abstract void RunTask(DdonGameServer server);
/// <summary>
/// Generates the next unix timestamp to store in the database for the task.
/// </summary>
/// <returns>Returns the unix timestamp which represents the next time this task should activate.</returns>
public abstract long NextTimestamp();
/// <summary>
/// By default, all tasks will return that they are enabled. A child class can override
/// this function to provide custom checks for enablement.
/// </summary>
/// <param name="server">The head server object</param>
/// <returns>Returns true if this task is enabled, otherwise false.</returns>
public virtual bool IsEnabled(DdonGameServer server)
{
return true;
}
/// <summary>
/// Returns the name of the task type.
/// </summary>
/// <returns></returns>
public abstract string TaskTypeName();
public virtual string TaskName()
{
return Type.ToString();
}
}
}