MCPcopy
hub / github.com/omkarcloud/botasaurus / run_task

Function run_task

botasaurus/task_decorator.py:70–142  ·  view source on GitHub ↗
(
                data,
                retry_attempt,
            )

Source from the content-addressed store, hash-verified

68 fn_name = func.__name__
69
70 def run_task(
71 data,
72 retry_attempt,
73 ) -> Any:
74 if cache is True:
75 # Returns {"data": value} or None
76 cached = storage.get(fn_name, data, expires_in)
77 if cached is not None:
78 return cached["data"]
79
80 result = None
81 try:
82 if "metadata" in kwargs or metadata is not None:
83 result = func(data, metadata)
84 else:
85 result = func(data)
86 if cache is True or cache == 'REFRESH':
87 if is_dont_cache(result):
88 storage.delete(fn_name, data)
89 else:
90 storage.put(fn_name, data, result)
91
92 if is_dont_cache(result):
93 if not return_dont_cache_as_is:
94 result = result.data
95 return result
96 except Exception as error:
97 if isinstance(error, KeyboardInterrupt):
98 raise # Re-raise the KeyboardInterrupt to stop execution
99 elif isinstance(error, NotFoundException) and not error.raised_once:
100 if error.raise_maximum_1_time:
101 error.raised_once = True
102 raise
103 elif (
104 must_raise_exceptions
105 and is_errors_instance(must_raise_exceptions, error)[0]
106 ):
107 if create_error_logs:
108 save_error_logs(format_exc(), None)
109 raise
110
111 if max_retry is not None and (max_retry) > (retry_attempt):
112 print_exc()
113 if retry_wait:
114 from time import sleep
115 print("Waiting for " + str(retry_wait) + " seconds")
116 sleep(retry_wait)
117 return run_task(data, retry_attempt + 1)
118
119 if not raise_exception:
120 print_exc()
121
122 print("Task failed for input:", data)
123 if create_error_logs:
124 save_error_logs(format_exc(), None)
125
126
127 if not IS_PRODUCTION:

Callers 2

wrapper_requestsFunction · 0.70
runFunction · 0.70

Calls 8

save_error_logsFunction · 0.90
is_dont_cacheFunction · 0.85
beep_inputFunction · 0.85
is_errors_instanceFunction · 0.70
sleepFunction · 0.50
getMethod · 0.45
deleteMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected