1
1
import os
2
2
import subprocess
3
+ from datetime import datetime , timezone
3
4
from subprocess import CompletedProcess
4
- from typing import Any , Callable , Dict , List , Optional
5
+ from typing import Any , Dict , List
5
6
6
7
from informaticsmatters .protobuf .datamanager .pod_message_pb2 import PodMessage
7
8
@@ -32,15 +33,27 @@ def launch(
32
33
* ,
33
34
project_id : str ,
34
35
workflow_id : str ,
36
+ running_workflow_step_id : str ,
35
37
workflow_definition : Dict [str , Any ],
36
38
step : str ,
37
39
step_specification : Dict [str , Any ],
38
- completion_callback : Optional [Callable [[PodMessage ], None ]],
39
40
) -> LaunchResult :
40
41
assert project_id
41
42
assert workflow_id
42
43
assert step_specification
43
44
45
+ # We're passed a RunningWorkflowStep ID but a record is expected to have been
46
+ # created bt the caller, we simply create instance records.
47
+ response = self ._api_adapter .get_running_workflow_step (
48
+ running_workflow_step_id = running_workflow_step_id
49
+ )
50
+ assert "running_workflow_step" in response
51
+ # Now simulate the creation of an Instance record
52
+ response = self ._api_adapter .create_instance (
53
+ running_workflow_step_id = running_workflow_step_id
54
+ )
55
+ instance_id = response ["instance_id" ]
56
+
44
57
# Just run the Python module that matched the 'job' in the step specification.
45
58
# Don't care about 'version' or 'collection'.
46
59
job : str = step_specification ["job" ]
@@ -52,10 +65,20 @@ def launch(
52
65
completed_process : CompletedProcess = subprocess .run (job_cmd , check = True )
53
66
assert completed_process .returncode == 0
54
67
68
+ # Simulate a PodMessage (that will contain the instance ID),
69
+ # filling-in only the fields that are of use to the Engine.
70
+ pod_message = PodMessage ()
71
+ pod_message .timestamp = f"{ datetime .now (timezone .utc ).isoformat ()} Z"
72
+ pod_message .phase = "Completed"
73
+ pod_message .instance = instance_id
74
+ pod_message .has_exit_code = True
75
+ pod_message .exit_code = 0
76
+ self ._msg_dispatcher .send (pod_message )
77
+
55
78
return LaunchResult (
56
79
error = 0 ,
57
80
error_msg = None ,
58
- instance_id = "instance-00000000-0000-0000-0000-000000000000" ,
81
+ instance_id = instance_id ,
59
82
task_id = "task-00000000-0000-0000-0000-000000000000" ,
60
83
command = " " .join (job_cmd ),
61
84
)
0 commit comments