1111from typing import (
1212 Any ,
1313 Optional ,
14+ Protocol ,
1415 Union ,
16+ runtime_checkable ,
1517)
1618
1719from cached_property import (
4850)
4951
5052
51- class RemoteSagaStepDecoratorWrapper (SagaStepDecoratorWrapper ):
53+ @runtime_checkable
54+ class RemoteSagaStepDecoratorWrapper (SagaStepDecoratorWrapper , Protocol ):
5255 """TODO"""
5356
5457 meta : RemoteSagaStepDecoratorMeta
@@ -150,11 +153,14 @@ def __call__(self, func: RequestCallBack) -> RemoteSagaStepDecoratorWrapper:
150153 return func
151154
152155 def on_execute (
153- self , callback : RequestCallBack , parameters : Optional [SagaContext ] = None , ** kwargs
156+ self ,
157+ operation : Union [SagaOperation [RequestCallBack ], RequestCallBack ],
158+ parameters : Optional [SagaContext ] = None ,
159+ ** kwargs ,
154160 ) -> RemoteSagaStep :
155161 """On execute method.
156162
157- :param callback : The callback function to be called.
163+ :param operation : The callback function to be called.
158164 :param parameters: A mapping of named parameters to be passed to the callback.
159165 :param kwargs: A set of named arguments to be passed to the callback. ``parameters`` has order if it is not
160166 ``None``.
@@ -163,16 +169,22 @@ def on_execute(
163169 if self .on_execute_operation is not None :
164170 raise MultipleOnExecuteException ()
165171
166- self .on_execute_operation = SagaOperation (callback , parameters , ** kwargs )
172+ if not isinstance (operation , SagaOperation ):
173+ operation = SagaOperation (operation , parameters , ** kwargs )
174+
175+ self .on_execute_operation = operation
167176
168177 return self
169178
170179 def on_failure (
171- self , callback : RequestCallBack , parameters : Optional [SagaContext ] = None , ** kwargs
180+ self ,
181+ operation : Union [SagaOperation [RequestCallBack ], RequestCallBack ],
182+ parameters : Optional [SagaContext ] = None ,
183+ ** kwargs ,
172184 ) -> RemoteSagaStep :
173185 """On failure method.
174186
175- :param callback : The callback function to be called.
187+ :param operation : The callback function to be called.
176188 :param parameters: A mapping of named parameters to be passed to the callback.
177189 :param kwargs: A set of named arguments to be passed to the callback. ``parameters`` has order if it is not
178190 ``None``.
@@ -181,16 +193,22 @@ def on_failure(
181193 if self .on_failure_operation is not None :
182194 raise MultipleOnFailureException ()
183195
184- self .on_failure_operation = SagaOperation (callback , parameters , ** kwargs )
196+ if not isinstance (operation , SagaOperation ):
197+ operation = SagaOperation (operation , parameters , ** kwargs )
198+
199+ self .on_failure_operation = operation
185200
186201 return self
187202
188203 def on_success (
189- self , callback : ResponseCallBack , parameters : Optional [SagaContext ] = None , ** kwargs
204+ self ,
205+ operation : Union [SagaOperation [ResponseCallBack ], ResponseCallBack ],
206+ parameters : Optional [SagaContext ] = None ,
207+ ** kwargs ,
190208 ) -> RemoteSagaStep :
191209 """On success method.
192210
193- :param callback : The callback function to be called.
211+ :param operation : The callback function to be called.
194212 :param parameters: A mapping of named parameters to be passed to the callback.
195213 :param kwargs: A set of named arguments to be passed to the callback. ``parameters`` has order if it is not
196214 ``None``.
@@ -199,16 +217,22 @@ def on_success(
199217 if self .on_success_operation is not None :
200218 raise MultipleOnSuccessException ()
201219
202- self .on_success_operation = SagaOperation (callback , parameters , ** kwargs )
220+ if not isinstance (operation , SagaOperation ):
221+ operation = SagaOperation (operation , parameters , ** kwargs )
222+
223+ self .on_success_operation = operation
203224
204225 return self
205226
206227 def on_error (
207- self , callback : ResponseCallBack , parameters : Optional [SagaContext ] = None , ** kwargs
228+ self ,
229+ operation : Union [SagaOperation [ResponseCallBack ], ResponseCallBack ],
230+ parameters : Optional [SagaContext ] = None ,
231+ ** kwargs ,
208232 ) -> RemoteSagaStep :
209233 """On error method.
210234
211- :param callback : The callback function to be called.
235+ :param operation : The callback function to be called.
212236 :param parameters: A mapping of named parameters to be passed to the callback.
213237 :param kwargs: A set of named arguments to be passed to the callback. ``parameters`` has order if it is not
214238 ``None``.
@@ -217,7 +241,10 @@ def on_error(
217241 if self .on_error_operation is not None :
218242 raise MultipleOnErrorException ()
219243
220- self .on_error_operation = SagaOperation (callback , parameters , ** kwargs )
244+ if not isinstance (operation , SagaOperation ):
245+ operation = SagaOperation (operation , parameters , ** kwargs )
246+
247+ self .on_error_operation = operation
221248
222249 return self
223250
0 commit comments