/
job.py
50 lines (38 loc) · 1.3 KB
/
job.py
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
import util
EXECUTION_TYPES = ["daily", "weekly", "monthly"]
WEEKDAYS = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]
class Job:
def __init__(self, recipeRef):
self.id = -1
self.recipeRef = recipeRef.strip()
self.executionType = "daily"
self.executionTime = util.parseTime("11:00")
self.isExecuting = False
def setExecution(self, type, time, day=None):
if type in EXECUTION_TYPES:
self.executionType = type
self.executionTime = time
self.executionDay = day
else:
raise JobException("Unknown execution type")
def setExecutionType(self, type):
if type in EXECUTION_TYPES:
self.executionType = type
if type == "weekly":
self.executionDay = "Mo"
if type == "monthly":
self.executionDay = 1
else:
raise JobException("Unknown execution type")
def setExecutionTime(self, time):
self.executionTime = time
def setExecutionDay(self, day):
self.executionDay = day
def __eq__(self, other):
if isinstance(other, Job):
return self.id == other.id
else:
return False
class JobException(Exception):
def __init__(self, message):
self.message = message