(*args, **kwargs)
| 37 | |
| 38 | @wraps(func) |
| 39 | def wrapper_requests(*args, **kwargs) -> Any: |
| 40 | print_running() |
| 41 | |
| 42 | nonlocal parallel, data, cache, expires_in, cache_storage, beep, run_async, async_queue, metadata |
| 43 | nonlocal close_on_crash, output, output_formats, max_retry, retry_wait, must_raise_exceptions, raise_exception, create_error_logs |
| 44 | |
| 45 | parallel = kwargs.get("parallel", parallel) |
| 46 | data = kwargs.get("data", data) |
| 47 | cache = kwargs.get("cache", cache) |
| 48 | expires_in = kwargs.get("expires_in", expires_in) |
| 49 | storage = kwargs.get("cache_storage", cache_storage) or FileCacheStorage |
| 50 | beep = kwargs.get("beep", beep) |
| 51 | run_async = kwargs.get("run_async", run_async) |
| 52 | metadata = kwargs.get("metadata", metadata) |
| 53 | async_queue = kwargs.get("async_queue", async_queue) |
| 54 | close_on_crash = kwargs.get("close_on_crash", close_on_crash) |
| 55 | output = kwargs.get("output", output) |
| 56 | output_formats = kwargs.get("output_formats", output_formats) |
| 57 | max_retry = kwargs.get("max_retry", max_retry) |
| 58 | retry_wait = kwargs.get("retry_wait", retry_wait) |
| 59 | # A Special Option passed by botasaurus server which prevents caching at database level |
| 60 | return_dont_cache_as_is = kwargs.get("return_dont_cache_as_is", False) |
| 61 | must_raise_exceptions = kwargs.get( |
| 62 | "must_raise_exceptions", must_raise_exceptions |
| 63 | ) |
| 64 | create_error_logs = kwargs.get("create_error_logs", create_error_logs) |
| 65 | |
| 66 | raise_exception = kwargs.get("raise_exception", raise_exception) |
| 67 | |
| 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: |
no test coverage detected