MCPcopy Create free account
hub / github.com/python-arq/arq / func

Function func

arq/worker.py:61–94  ·  view source on GitHub ↗

Wrapper for a job function which lets you configure more settings. :param coroutine: coroutine function to call, can be a string to import :param name: name for function, if None, ``coroutine.__qualname__`` is used :param keep_result: duration to keep the result for, if 0 the resul

(
    coroutine: Union[str, Function, 'WorkerCoroutine'],
    *,
    name: Optional[str] = None,
    keep_result: Optional['SecondsTimedelta'] = None,
    timeout: Optional['SecondsTimedelta'] = None,
    keep_result_forever: Optional[bool] = None,
    max_tries: Optional[int] = None,
)

Source from the content-addressed store, hash-verified

59
60
61def func(
62 coroutine: Union[str, Function, 'WorkerCoroutine'],
63 *,
64 name: Optional[str] = None,
65 keep_result: Optional['SecondsTimedelta'] = None,
66 timeout: Optional['SecondsTimedelta'] = None,
67 keep_result_forever: Optional[bool] = None,
68 max_tries: Optional[int] = None,
69) -> Function:
70 """
71 Wrapper for a job function which lets you configure more settings.
72
73 :param coroutine: coroutine function to call, can be a string to import
74 :param name: name for function, if None, ``coroutine.__qualname__`` is used
75 :param keep_result: duration to keep the result for, if 0 the result is not kept
76 :param keep_result_forever: whether to keep results forever, if None use Worker default, wins over ``keep_result``
77 :param timeout: maximum time the job should take
78 :param max_tries: maximum number of tries allowed for the function, use 1 to prevent retrying
79 """
80 if isinstance(coroutine, Function):
81 return coroutine
82
83 if isinstance(coroutine, str):
84 name = name or coroutine
85 coroutine_: WorkerCoroutine = import_string(coroutine)
86 else:
87 coroutine_ = coroutine
88
89 if not inspect.iscoroutinefunction(coroutine_):
90 raise RuntimeError(f'{coroutine_} is not a coroutine function')
91 timeout = to_seconds(timeout)
92 keep_result = to_seconds(keep_result)
93
94 return Function(name or coroutine_.__qualname__, coroutine_, timeout, keep_result, keep_result_forever, max_tries)
95
96
97class Retry(RuntimeError):

Callers 15

SettingsClass · 0.90
test_job_retryFunction · 0.90
test_job_retry_max_jobsFunction · 0.90
test_retry_lotsFunction · 0.90
test_retry_lots_checkFunction · 0.90
test_cancel_errorFunction · 0.90
test_retry_job_errorFunction · 0.90

Calls 3

import_stringFunction · 0.85
to_secondsFunction · 0.85
FunctionClass · 0.85

Tested by 15

test_job_retryFunction · 0.72
test_job_retry_max_jobsFunction · 0.72
test_retry_lotsFunction · 0.72
test_retry_lots_checkFunction · 0.72
test_cancel_errorFunction · 0.72
test_retry_job_errorFunction · 0.72
test_unpickleableFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…