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

Function cron

arq/cron.py:128–200  ·  view source on GitHub ↗

Create a cron job, eg. it should be executed at specific times. Workers will enqueue this job at or just after the set times. If ``unique`` is true (the default) the job will only be run once even if multiple workers are running. :param coroutine: coroutine function to run :pa

(
    coroutine: Union[str, WorkerCoroutine],
    *,
    name: Optional[str] = None,
    month: OptionType = None,
    day: OptionType = None,
    weekday: WeekdayOptionType = None,
    hour: OptionType = None,
    minute: OptionType = None,
    second: OptionType = 0,
    microsecond: int = 123_456,
    run_at_startup: bool = False,
    unique: bool = True,
    job_id: Optional[str] = None,
    timeout: Optional[SecondsTimedelta] = None,
    keep_result: Optional[float] = 0,
    keep_result_forever: Optional[bool] = False,
    max_tries: Optional[int] = 1,
)

Source from the content-addressed store, hash-verified

126
127
128def cron(
129 coroutine: Union[str, WorkerCoroutine],
130 *,
131 name: Optional[str] = None,
132 month: OptionType = None,
133 day: OptionType = None,
134 weekday: WeekdayOptionType = None,
135 hour: OptionType = None,
136 minute: OptionType = None,
137 second: OptionType = 0,
138 microsecond: int = 123_456,
139 run_at_startup: bool = False,
140 unique: bool = True,
141 job_id: Optional[str] = None,
142 timeout: Optional[SecondsTimedelta] = None,
143 keep_result: Optional[float] = 0,
144 keep_result_forever: Optional[bool] = False,
145 max_tries: Optional[int] = 1,
146) -> CronJob:
147 """
148 Create a cron job, eg. it should be executed at specific times.
149
150 Workers will enqueue this job at or just after the set times. If ``unique`` is true (the default) the
151 job will only be run once even if multiple workers are running.
152
153 :param coroutine: coroutine function to run
154 :param name: name of the job, if None, the name of the coroutine is used
155 :param month: month(s) to run the job on, 1 - 12
156 :param day: day(s) to run the job on, 1 - 31
157 :param weekday: week day(s) to run the job on, 0 - 6 or mon - sun
158 :param hour: hour(s) to run the job on, 0 - 23
159 :param minute: minute(s) to run the job on, 0 - 59
160 :param second: second(s) to run the job on, 0 - 59
161 :param microsecond: microsecond(s) to run the job on,
162 defaults to 123456 as the world is busier at the top of a second, 0 - 1e6
163 :param run_at_startup: whether to run as worker starts
164 :param unique: whether the job should only be executed once at each time (useful if you have multiple workers)
165 :param job_id: ID of the job, can be used to enforce job uniqueness, spanning multiple cron schedules
166 :param timeout: job timeout
167 :param keep_result: how long to keep the result for
168 :param keep_result_forever: whether to keep results forever
169 :param max_tries: maximum number of tries for the job
170 """
171
172 if isinstance(coroutine, str):
173 name = name or 'cron:' + coroutine
174 coroutine_: WorkerCoroutine = import_string(coroutine)
175 else:
176 coroutine_ = coroutine
177
178 if not inspect.iscoroutinefunction(coroutine_):
179 raise RuntimeError(f'{coroutine_} is not a coroutine function')
180 timeout = to_seconds(timeout)
181 keep_result = to_seconds(keep_result)
182
183 return CronJob(
184 name or 'cron:' + coroutine_.__qualname__,
185 coroutine_,

Callers 11

test_job_successfulFunction · 0.90
test_not_runFunction · 0.90
test_reprFunction · 0.90
test_str_functionFunction · 0.90
test_cron_cancelledFunction · 0.90
test_job_custom_idFunction · 0.90
WorkerSettingsClass · 0.90

Calls 3

import_stringFunction · 0.85
to_secondsFunction · 0.85
CronJobClass · 0.85

Tested by 10

test_job_successfulFunction · 0.72
test_not_runFunction · 0.72
test_reprFunction · 0.72
test_str_functionFunction · 0.72
test_cron_cancelledFunction · 0.72
test_job_custom_idFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…