|
@@ -1,134 +0,0 @@
|
1
|
|
-module stratos.job;
|
2
|
|
-
|
3
|
|
-import core.time, std.datetime;
|
4
|
|
-
|
5
|
|
-/// The definition of a job.
|
6
|
|
-class JobDef
|
7
|
|
-{
|
8
|
|
- /// The friendly name of the job.
|
9
|
|
- string name;
|
10
|
|
-
|
11
|
|
- /**
|
12
|
|
- * The version number for this job.
|
13
|
|
- *
|
14
|
|
- * Multiple jobs with the same name are considered versions of the same job.
|
15
|
|
- * The newest job wins, replacing previous ones.
|
16
|
|
- */
|
17
|
|
- size_t versionNumber;
|
18
|
|
-
|
19
|
|
- /// Which ports it needs to run on. We'll use network trickery to make sure it always works.
|
20
|
|
- ushort[] ports;
|
21
|
|
-
|
22
|
|
- /// How often to run it, how many instances, etc.
|
23
|
|
- Schedule schedule;
|
24
|
|
-
|
25
|
|
- /// How to determine if it's healthy.
|
26
|
|
- HealthCheck healthcheck;
|
27
|
|
-
|
28
|
|
- /**
|
29
|
|
- * How long it takes to drain instances of this service.
|
30
|
|
- *
|
31
|
|
- * When you gracefully terminate a task, its DNS records are removed. Once the DNS cache gets flushed, we
|
32
|
|
- * wait this long for the last requests to be finished before stopping the task.
|
33
|
|
- *
|
34
|
|
- * When you restart a task, update a job, etc, we bring up the new task first, wait for it to become healthy,
|
35
|
|
- * then undertake the process described.
|
36
|
|
- */
|
37
|
|
- Duration drainTime = 30.seconds;
|
38
|
|
-}
|
39
|
|
-
|
40
|
|
-/**
|
41
|
|
- * How and when to run a job.
|
42
|
|
- * This is a little combinatorial, but some options:
|
43
|
|
- *
|
44
|
|
- * {instances=1, restart=always, period=0}
|
45
|
|
- * Run this continually, but only once instance.
|
46
|
|
- *
|
47
|
|
- * {instances=2, restart=never, period=0}
|
48
|
|
- * Run this right now, two copies; don't restart. One-off job.
|
49
|
|
- *
|
50
|
|
- * {instances=1, restart=never, period=8h}
|
51
|
|
- * Start this every eight hours; don't restart.
|
52
|
|
- *
|
53
|
|
- * {instances=1, restart=onerror, period=1h}
|
54
|
|
- * Start this every hour. If it fails early with an error, rerun it.
|
55
|
|
- * This will not run the job multiple overlapping times.
|
56
|
|
- */
|
57
|
|
-class Schedule
|
58
|
|
-{
|
59
|
|
- /// How to handle restarts.
|
60
|
|
- enum Restart
|
61
|
|
- {
|
62
|
|
- /// Restart this thing if it exits, cleanly or otherwise.
|
63
|
|
- Always,
|
64
|
|
- /// Don't restart this thing, no matter why it fails.
|
65
|
|
- Never,
|
66
|
|
- /// Restart this thing if it fails, not if it exits cleanly.
|
67
|
|
- OnError,
|
68
|
|
- }
|
69
|
|
-
|
70
|
|
- /// How many instances should be run at once.
|
71
|
|
- size_t instances = 1;
|
72
|
|
- /// Whether to restart if a task ends.
|
73
|
|
- Restart restart = Restart.Always;
|
74
|
|
- /// How frequently to run this task.
|
75
|
|
- Duration period = Duration.zero;
|
76
|
|
-}
|
77
|
|
-
|
78
|
|
-struct JobID
|
79
|
|
-{
|
80
|
|
- string name;
|
81
|
|
- size_t revision;
|
82
|
|
-}
|
83
|
|
-
|
84
|
|
-/// A Task is a process run for a job.
|
85
|
|
-class Task
|
86
|
|
-{
|
87
|
|
- /// The corresponding job.
|
88
|
|
- JobDef job;
|
89
|
|
- /// When this started running.
|
90
|
|
- SysTime start;
|
91
|
|
- /// When this stopped running. SysTime.min if it's still ongoing.
|
92
|
|
- SysTime end;
|
93
|
|
- /// If this process has exited, this is its exit code.
|
94
|
|
- int exitCode;
|
95
|
|
- /// The name of the instance that is running / ran this job.
|
96
|
|
- string runningInstance;
|
97
|
|
- /// The path at which ith sshould have run.
|
98
|
|
- string logPath;
|
99
|
|
-}
|
100
|
|
-
|
101
|
|
-/// A HealthCheck is how we determine service health.
|
102
|
|
-class HealthCheck
|
103
|
|
-{
|
104
|
|
- /// What type of healthcheck to perform.
|
105
|
|
- enum Type
|
106
|
|
- {
|
107
|
|
- /// Perform an HTTP(S) GET request, using the status code to determine health.
|
108
|
|
- HTTP,
|
109
|
|
- /// Connect to a socket. Successful connection means healthy.
|
110
|
|
- Socket
|
111
|
|
- }
|
112
|
|
-
|
113
|
|
- /// This healthcheck's type.
|
114
|
|
- Type type;
|
115
|
|
- /// If HTTP, request the given path.
|
116
|
|
- string httpPath = "/";
|
117
|
|
- /// Whether to make an SSL request.
|
118
|
|
- bool ssl = false;
|
119
|
|
- /// What port to request. If not specified, HTTPS gets port 443, HTTP gets port 80.
|
120
|
|
- // TODO is this necessary? Jobs will specify which ports they get.
|
121
|
|
- ushort port = 0;
|
122
|
|
-
|
123
|
|
- /// How frequently to check job health.
|
124
|
|
- Duration interval = seconds(30);
|
125
|
|
- /// Services might take extra time to warm up. This is how much extra time to give.
|
126
|
|
- Duration startupGracePeriod = seconds(60);
|
127
|
|
-
|
128
|
|
- /// How many checks in a row to succeed before calling this healthy.
|
129
|
|
- ushort healthyCount = 2;
|
130
|
|
- /// How many checks in a row to fail before calling this unhealthy (and then we'll stop routing traffic).
|
131
|
|
- ushort unhealthyCount = 1;
|
132
|
|
- /// How many checks in a row to fail before calling this unhealthy (and then we'll restart the task).
|
133
|
|
- ushort respawnCount = 5;
|
134
|
|
-}
|