-
Notifications
You must be signed in to change notification settings - Fork 1
/
task_state.py
60 lines (42 loc) · 1.25 KB
/
task_state.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
51
52
53
54
55
56
57
58
59
60
class TaskState(object):
name = "state"
allowed = []
def switch(self, state):
""" Switch to new state """
if state.name in self.allowed:
print('Current:', self, ' => switched to new state', state.name)
self.__class__ = state
else:
print('Current:', self, ' => switching to', state.name, 'not possible.')
def __str__(self):
return self.name
class NA(TaskState):
name = "na"
allowed = ['started']
class Started(TaskState):
name = "started"
allowed = ['stop', 'completed']
class Running(TaskState):
""" State of being running """
name = "running"
allowed = ['stopped', 'canceled', 'completed']
class Stopped(TaskState):
""" State of being running """
name = "stopped"
allowed = ['Canceled', 'Resume']
class Canceled(TaskState):
""" State of being running """
name = "canceled"
allowed = ['Resume']
class Completed(TaskState):
""" State of being running """
name = "completed"
allowed = []
class Resume(TaskState):
""" State of being running """
name = "canceled"
allowed = ['running', 'failed']
class Failed(TaskState):
""" State of being running """
name = "failed"
allowed = ['started']