13
13
_JOB_DEFINITIONS : Dict [str , Any ] = yaml .load (jd_file , Loader = yaml .FullLoader )
14
14
assert _JOB_DEFINITIONS
15
15
16
+ _INSTANCE_ID_FORMAT : str = "instance-00000000-0000-0000-0000-{id:012d}"
16
17
_WORKFLOW_DEFINITION_ID_FORMAT : str = "workflow-00000000-0000-0000-0000-{id:012d}"
17
18
_RUNNING_WORKFLOW_ID_FORMAT : str = "r-workflow-00000000-0000-0000-0000-{id:012d}"
18
19
_RUNNING_WORKFLOW_STEP_ID_FORMAT : str = (
@@ -31,8 +32,9 @@ def __init__(self):
31
32
self ._workflow_definitions : Dict [str , Dict [str , Any ]] = {}
32
33
self ._running_workflow : Dict [str , Dict [str , Any ]] = {}
33
34
self ._running_workflow_steps : Dict [str , Dict [str , Any ]] = {}
35
+ self ._instances : Dict [str , Dict [str , Any ]] = {}
34
36
35
- def save_workflow (self , * , workflow_definition : Dict [str , Any ]) -> str :
37
+ def create_workflow (self , * , workflow_definition : Dict [str , Any ]) -> str :
36
38
next_id : int = len (self ._workflow_definitions ) + 1
37
39
workflow_definition_id : str = _WORKFLOW_DEFINITION_ID_FORMAT .format (id = next_id )
38
40
self ._workflow_definitions [workflow_definition_id ] = workflow_definition
@@ -60,17 +62,20 @@ def create_running_workflow(self, *, workflow_definition_id: str) -> str:
60
62
def get_running_workflow (self , * , running_workflow_id : str ) -> Dict [str , Any ]:
61
63
if running_workflow_id not in self ._running_workflow :
62
64
return {}
63
- return {"running-workflow " : self ._running_workflow [running_workflow_id ]}
65
+ return {"running_workflow " : self ._running_workflow [running_workflow_id ]}
64
66
65
- def create_running_workflow_step (self , * , running_workflow_id : str ) -> str :
67
+ def create_running_workflow_step (
68
+ self , * , running_workflow_id : str , step : str
69
+ ) -> str :
66
70
next_id : int = len (self ._running_workflow_steps ) + 1
67
71
running_workflow_step_id : str = _RUNNING_WORKFLOW_STEP_ID_FORMAT .format (
68
72
id = next_id
69
73
)
70
74
record = {
75
+ "step" : step ,
71
76
"done" : False ,
72
77
"success" : False ,
73
- "running-workflow " : running_workflow_id ,
78
+ "running_workflow " : running_workflow_id ,
74
79
}
75
80
self ._running_workflow_steps [running_workflow_step_id ] = record
76
81
return {"id" : running_workflow_step_id }
@@ -80,17 +85,35 @@ def get_running_workflow_step(
80
85
) -> Dict [str , Any ]:
81
86
if running_workflow_step_id not in self ._running_workflow_steps :
82
87
return {}
83
- return {"id" : self ._running_workflow_steps [running_workflow_step_id ]}
88
+ return {
89
+ "running_workflow_step" : self ._running_workflow_steps [
90
+ running_workflow_step_id
91
+ ]
92
+ }
84
93
85
94
def get_running_workflow_steps (
86
95
self , * , running_workflow_id : str
87
96
) -> List [Dict [str , Any ]]:
88
97
steps = []
89
98
for key , value in self ._running_workflow_steps .items ():
90
- if value ["running-workflow " ] == running_workflow_id :
91
- item = {"running-workflow-step " : value , "id" : key }
99
+ if value ["running_workflow " ] == running_workflow_id :
100
+ item = {"running_workflow_step " : value , "id" : key }
92
101
steps .append (item )
93
- return {"count" : len (steps ), "running-workflow-steps" : steps }
102
+ return {"count" : len (steps ), "running_workflow_steps" : steps }
103
+
104
+ def create_instance (self , * , running_workflow_step_id : str ) -> Dict [str , Any ]:
105
+ next_id : int = len (self ._instances ) + 1
106
+ instance_id : str = _INSTANCE_ID_FORMAT .format (id = next_id )
107
+ record = {
108
+ "running_workflow_step" : running_workflow_step_id ,
109
+ }
110
+ self ._instances [instance_id ] = record
111
+ return {"instance_id" : running_workflow_step_id }
112
+
113
+ def get_instance (self , * , instance_id : str ) -> Dict [str , Any ]:
114
+ if instance_id not in self ._instances :
115
+ return {}
116
+ return {self ._instances [instance_id ]}
94
117
95
118
def get_job (
96
119
self , * , collection : str , job : str , version : str
0 commit comments