5
5
from typing import Any
6
6
7
7
from .decoder import validate_schema
8
- from .workflow_abc import MessageDispatcher , WorkflowAPIAdapter
9
8
10
9
11
10
class ValidationLevel (Enum ):
@@ -20,47 +19,22 @@ class ValidationLevel(Enum):
20
19
class ValidationResult :
21
20
"""Workflow validation results."""
22
21
23
- error : int
22
+ error_num : int
24
23
error_msg : list [str ] | None
25
24
26
25
27
- @dataclass
28
- class StartResult :
29
- """WorkflowEngine start workflow result."""
30
-
31
- error : int
32
- error_msg : str | None
33
- running_workflow_id : str | None
34
-
35
-
36
- @dataclass
37
- class StopResult :
38
- """WorkflowEngine stop workflow result."""
39
-
40
- error : int
41
- error_msg : str | None
42
-
43
-
44
26
# Handy successful results
45
- _VALIDATION_SUCCESS = ValidationResult (error = 0 , error_msg = None )
46
- _SUCCESS_STOP_RESULT : StopResult = StopResult (error = 0 , error_msg = None )
27
+ _VALIDATION_SUCCESS = ValidationResult (error_num = 0 , error_msg = None )
47
28
48
29
49
30
class WorkflowValidator :
50
31
"""The workflow validator. Typically used from the context of the API
51
32
to check workflow content prior to creation and execution.
52
33
"""
53
34
54
- def __init__ (
55
- self , * , wapi_adapter : WorkflowAPIAdapter , msg_dispatcher : MessageDispatcher
56
- ):
57
- assert wapi_adapter
58
-
59
- self ._wapi_adapter = wapi_adapter
60
- self ._msg_dispatcher = msg_dispatcher
61
-
35
+ @classmethod
62
36
def validate (
63
- self ,
37
+ cls ,
64
38
* ,
65
39
level : ValidationLevel ,
66
40
workflow_definition : dict [str , Any ],
@@ -74,42 +48,6 @@ def validate(
74
48
assert isinstance (workflow_inputs , dict )
75
49
76
50
if error := validate_schema (workflow_definition ):
77
- return ValidationResult (error = 1 , error_msg = [error ])
51
+ return ValidationResult (error_num = 1 , error_msg = [error ])
78
52
79
53
return _VALIDATION_SUCCESS
80
-
81
- def start (
82
- self ,
83
- * ,
84
- project_id : str ,
85
- workflow_id : str ,
86
- workflow_definition : dict [str , Any ],
87
- workflow_parameters : dict [str , Any ],
88
- ) -> StartResult :
89
- """Called to initiate workflow by finding the first Instance (or instances)
90
- to run and then launching them. It is used from the API Pod, and apart from
91
- validating the workflow definition for suitability it sends a Start message
92
- to the internal message bus.
93
- """
94
- assert project_id
95
- assert workflow_id
96
- assert workflow_definition
97
- assert workflow_parameters
98
-
99
- return StartResult (
100
- error = 0 ,
101
- error_msg = None ,
102
- running_workflow_id = "r-workflow-6aacd971-ca87-4098-bb70-c1c5f19f4dbf" ,
103
- )
104
-
105
- def stop (
106
- self ,
107
- * ,
108
- running_workflow_id : str ,
109
- ) -> StopResult :
110
- """Stop a running workflow. It is used from the API Pod, and apart from
111
- validating the workflow definition for suitability it sends a Stop message
112
- to the internal message bus."""
113
- assert running_workflow_id
114
-
115
- return _SUCCESS_STOP_RESULT
0 commit comments