@@ -68,32 +68,34 @@ def _make_activity_wrapper(fn: Activity, logger: Logger) -> ActivityWrapper:
6868 """
6969 accepts_input , input_model = _model_protocol .resolve_input (fn )
7070
71+ def _call_args (ctx : task .ActivityContext , inp : object | None ) -> tuple :
72+ wf_ctx = WorkflowActivityContext (ctx )
73+ if not accepts_input :
74+ return (wf_ctx ,)
75+ return (wf_ctx , _coerce_activity_input (inp , input_model ))
76+
77+ def _log_failure (ctx : task .ActivityContext , exc : Exception ) -> None :
78+ activity_id = getattr (ctx , 'task_id' , 'unknown' )
79+ logger .warning (f'Activity execution failed - task_id: { activity_id } , error: { exc } ' )
80+
7181 if _is_async_callable (fn ):
7282
7383 async def async_activity_wrapper (
7484 ctx : task .ActivityContext , inp : object | None = None
7585 ) -> object :
76- activity_id = getattr (ctx , 'task_id' , 'unknown' )
7786 try :
78- wf_ctx = WorkflowActivityContext (ctx )
79- if not accepts_input :
80- return await fn (wf_ctx )
81- return await fn (wf_ctx , _coerce_activity_input (inp , input_model ))
82- except Exception as e :
83- logger .warning (f'Activity execution failed - task_id: { activity_id } , error: { e } ' )
87+ return await fn (* _call_args (ctx , inp ))
88+ except Exception as exc :
89+ _log_failure (ctx , exc )
8490 raise
8591
8692 return async_activity_wrapper
8793
8894 def sync_activity_wrapper (ctx : task .ActivityContext , inp : object | None = None ) -> object :
89- activity_id = getattr (ctx , 'task_id' , 'unknown' )
9095 try :
91- wf_ctx = WorkflowActivityContext (ctx )
92- if not accepts_input :
93- return fn (wf_ctx )
94- return fn (wf_ctx , _coerce_activity_input (inp , input_model ))
95- except Exception as e :
96- logger .warning (f'Activity execution failed - task_id: { activity_id } , error: { e } ' )
96+ return fn (* _call_args (ctx , inp ))
97+ except Exception as exc :
98+ _log_failure (ctx , exc )
9799 raise
98100
99101 return sync_activity_wrapper
0 commit comments