2020from conductor .shared .worker .exception import NonRetryableException
2121from conductor .client .worker .worker_interface import WorkerInterface
2222
23- ExecuteTaskFunction = Callable [
24- [
25- Union [Task , object ]
26- ],
27- Union [TaskResult , object ]
28- ]
23+ ExecuteTaskFunction = Callable [[Union [Task , object ]], Union [TaskResult , object ]]
2924
30- logger = logging .getLogger (
31- Configuration .get_logging_formatted_name (
32- __name__
33- )
34- )
25+ logger = logging .getLogger (Configuration .get_logging_formatted_name (__name__ ))
3526
3627
37- def is_callable_input_parameter_a_task (callable : ExecuteTaskFunction , object_type : Any ) -> bool :
28+ def is_callable_input_parameter_a_task (
29+ callable : ExecuteTaskFunction , object_type : Any
30+ ) -> bool :
3831 parameters = inspect .signature (callable ).parameters
3932 if len (parameters ) != 1 :
4033 return False
4134 parameter = parameters [next (iter (parameters .keys ()))]
42- return parameter .annotation == object_type or parameter .annotation == parameter .empty or parameter .annotation is object # noqa: PLR1714
35+ return (
36+ parameter .annotation == object_type
37+ or parameter .annotation == parameter .empty
38+ or parameter .annotation is object
39+ ) # noqa: PLR1714
4340
4441
45- def is_callable_return_value_of_type (callable : ExecuteTaskFunction , object_type : Any ) -> bool :
42+ def is_callable_return_value_of_type (
43+ callable : ExecuteTaskFunction , object_type : Any
44+ ) -> bool :
4645 return_annotation = inspect .signature (callable ).return_annotation
4746 return return_annotation == object_type
4847
4948
5049class Worker (WorkerInterface ):
51- def __init__ (self ,
52- task_definition_name : str ,
53- execute_function : ExecuteTaskFunction ,
54- poll_interval : Optional [float ] = None ,
55- domain : Optional [str ] = None ,
56- worker_id : Optional [str ] = None ,
57- ) -> Self :
50+ def __init__ (
51+ self ,
52+ task_definition_name : str ,
53+ execute_function : ExecuteTaskFunction ,
54+ poll_interval : Optional [float ] = None ,
55+ domain : Optional [str ] = None ,
56+ worker_id : Optional [str ] = None ,
57+ ) -> Self :
5858 super ().__init__ (task_definition_name )
5959 self .api_client = ApiClient ()
6060 self .config = Configuration ()
@@ -91,7 +91,9 @@ def execute(self, task: Task) -> TaskResult:
9191 if typ in utils .simple_types :
9292 task_input [input_name ] = task .input_data [input_name ]
9393 else :
94- task_input [input_name ] = convert_from_dict_or_list (typ , task .input_data [input_name ])
94+ task_input [input_name ] = convert_from_dict_or_list (
95+ typ , task .input_data [input_name ]
96+ )
9597 elif default_value is not inspect .Parameter .empty :
9698 task_input [input_name ] = default_value
9799 else :
@@ -118,8 +120,11 @@ def execute(self, task: Task) -> TaskResult:
118120 task .task_id ,
119121 )
120122
121- task_result .logs = [TaskExecLog (
122- traceback .format_exc (), task_result .task_id , int (time .time ()))]
123+ task_result .logs = [
124+ TaskExecLog (
125+ traceback .format_exc (), task_result .task_id , int (time .time ())
126+ )
127+ ]
123128 task_result .status = TaskResultStatus .FAILED
124129 if len (ne .args ) > 0 :
125130 task_result .reason_for_incompletion = ne .args [0 ]
@@ -130,7 +135,9 @@ def execute(self, task: Task) -> TaskResult:
130135 return task_result
131136 if not isinstance (task_result .output_data , dict ):
132137 task_output = task_result .output_data
133- task_result .output_data = self .api_client .sanitize_for_serialization (task_output )
138+ task_result .output_data = self .api_client .sanitize_for_serialization (
139+ task_output
140+ )
134141 if not isinstance (task_result .output_data , dict ):
135142 task_result .output_data = {"result" : task_result .output_data }
136143
@@ -146,11 +153,15 @@ def execute_function(self) -> ExecuteTaskFunction:
146153 @execute_function .setter
147154 def execute_function (self , execute_function : ExecuteTaskFunction ) -> None :
148155 self ._execute_function = execute_function
149- self ._is_execute_function_input_parameter_a_task = is_callable_input_parameter_a_task (
150- callable = execute_function ,
151- object_type = Task ,
156+ self ._is_execute_function_input_parameter_a_task = (
157+ is_callable_input_parameter_a_task (
158+ callable = execute_function ,
159+ object_type = Task ,
160+ )
152161 )
153- self ._is_execute_function_return_value_a_task_result = is_callable_return_value_of_type (
154- callable = execute_function ,
155- object_type = TaskResult ,
162+ self ._is_execute_function_return_value_a_task_result = (
163+ is_callable_return_value_of_type (
164+ callable = execute_function ,
165+ object_type = TaskResult ,
166+ )
156167 )
0 commit comments