13
13
14
14
# generate result_dic
15
15
from flybirds .core .global_context import GlobalContext
16
+ import time
16
17
17
18
if six .PY2 :
18
19
# -- USE PYTHON3 BACKPORT: With unicode traceback support.
19
20
import traceback2 as traceback
20
21
else :
21
22
import traceback
22
23
24
+ import asyncio
25
+ import nest_asyncio
26
+
27
+ nest_asyncio .apply ()
28
+ tim_loop = asyncio .new_event_loop ()
29
+
30
+
31
+ async def sleep_t (t ):
32
+ await asyncio .sleep (t )
33
+
34
+
35
+ def sleep (sleep_time ):
36
+ tim_loop .run_until_complete (sleep_t (sleep_time ))
37
+
23
38
24
39
def add_res_dic (dsl_params , functin_pattern , def_key ):
25
40
result_dic = {}
@@ -250,3 +265,44 @@ def wrapper(*args, **kwargs):
250
265
return func (* args , ** kwargs )
251
266
252
267
return wrapper
268
+
269
+
270
+ class RetryType :
271
+ def __init__ (self , * args , ** kwargs ): # 类装饰器参数
272
+ self .retry = args [0 ]
273
+
274
+ def __call__ (self , func ): # 被装饰函数
275
+ @wraps (func )
276
+ def wrapper (* args , ** kwargs ):
277
+ if gr .get_platform () is not None \
278
+ and gr .get_platform ().lower () == "web" :
279
+ self .retryTimeOut = gr .get_frame_config_value ("retry_ele_timeout" , 30 )
280
+
281
+ self .waitTimeInterval = max (self .retryTimeOut // 30 , 1 )
282
+ self .retryTimes = max (self .retryTimeOut // self .waitTimeInterval , 1 )
283
+ self .recordMaxRetryTimes = self .retryTimes
284
+ self .runSuccess = False
285
+ log .info (
286
+ f'retry start retryTimeOut: { self .retryTimeOut } s, self.waitTimeInterval: { self .waitTimeInterval } s, maxRetryTimes: { self .recordMaxRetryTimes } ' )
287
+ while self .retryTimes > 0 :
288
+ try :
289
+ func (* args , ** kwargs )
290
+ self .runSuccess = True
291
+ if self .runSuccess == True :
292
+ log .info (
293
+ f'retry success, max retry times: { self .recordMaxRetryTimes } , retry times: { self .recordMaxRetryTimes - self .retryTimes } ' )
294
+ break
295
+ except Exception as e :
296
+ self .retryTimes -= 1
297
+ if self .retryTimes == 0 :
298
+ log .info (f'retry fail during { self .retryTimeOut } s, retry times: { self .recordMaxRetryTimes } ' )
299
+ raise e
300
+ else :
301
+ log .info (
302
+ f'retry sleep interval { self .waitTimeInterval } s,current retry times: { self .recordMaxRetryTimes - self .retryTimes } ' )
303
+ sleep (self .waitTimeInterval )
304
+ pass
305
+ else :
306
+ func (* args , ** kwargs )
307
+
308
+ return wrapper
0 commit comments