Skip to content

Commit 2b5b124

Browse files
committed
adding docs for cron, fix #51
1 parent df78a61 commit 2b5b124

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

arq/main.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -291,33 +291,35 @@ def __repr__(self):
291291

292292

293293
def cron(*,
294-
dft_queue=None,
295-
run_at_startup=False,
296-
unique=True,
297294
month: Union[None, set, int]=None,
298295
day: Union[None, set, int]=None,
299296
weekday: Union[None, set, int, str]=None,
300297
hour: Union[None, set, int]=None,
301298
minute: Union[None, set, int]=None,
302299
second: Union[None, set, int]=0,
303-
microsecond: int=123456):
300+
microsecond: int=123456,
301+
dft_queue=None,
302+
run_at_startup=False,
303+
unique=True):
304304
"""
305+
Decorator which defines a functions as a cron job, eg. it should be executed at specific times.
305306
306-
Decorator which defines a functions as a cron job, eg. it should be executed at specific times...
307+
Workers will enqueue this job at or just after the set times. If ``unique`` is true (the default) the
308+
job will only be enqueued once even if multiple workers are running.
307309
308310
If you wish to call the function directly you can access the original function at ``<func>.direct``.
309311
310-
:param dft_queue: default queue to use
311-
:param run_at_startup: whether to run as worker starts
312-
:param unique: whether the job should be only be executed on one worker.
313312
:param month: month(s) to run the job on, 1 - 12
314313
:param day: day(s) to run the job on, 1 - 31
315314
:param weekday: week day(s) to run the job on, 0 - 6 or mon - sun
316315
:param hour: hour(s) to run the job on, 0 - 23
317316
:param minute: minute(s) to run the job on, 0 - 59
318317
:param second: second(s) to run the job on, 0 - 59
319318
:param microsecond: microsecond(s) to run the job on,
320-
defaults to 123456 as the world is busier at the top of a second 0 - 1e6
319+
defaults to 123456 as the world is busier at the top of a second, 0 - 1e6
320+
:param dft_queue: default queue to use
321+
:param run_at_startup: whether to run as worker starts
322+
:param unique: whether the job should be only be executed once at each time
321323
"""
322324

323325
return lambda f: CronJob(

docs/examples/cron.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from arq import Actor, cron
2+
3+
4+
class FooBar(Actor):
5+
6+
@cron(hour={9, 12, 18}, minute=12)
7+
async def foo(self):
8+
print('run foo job at 9.12am, 12.12pm and 6.12pm')

docs/examples/direct_enqueuing.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ async def main():
1010
foobar = FooBar()
1111
await foobar.enqueue_job('foo', 1, 2, c=48, queue=Actor.LOW_QUEUE)
1212
await foobar.enqueue_job('foo', 1, 2, c=48) # this will be queued in DEFAULT_QUEUE
13+
await foobar.close()

docs/usage.rst

+16
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ Where the items have the following meaning:
6161
* ``j_ongoing`` the number of jobs currently being performed
6262
* ``q_*`` the number of pending jobs in each queue
6363

64+
Cron Jobs
65+
.........
66+
67+
Functions can be scheduled to be run periodically at specific times
68+
69+
.. literalinclude:: examples/cron.py
70+
71+
See :meth:`arq.main.cron` for details on the available arguments and how how cron works.
72+
73+
Usage roughly shadows `cron <https://helpmanual.io/man8/cron/>`_ except ``None`` is equivilent on ``*`` in crontab.
74+
As per the example sets can be used to run at multiple of the given unit.
75+
76+
Note that ``second`` defaults to ``0`` so you don't in inadvertently run jobs every second and ``microsecond``
77+
defaults to ``123456`` so you don't inadvertently run jobs every microsecond and so *arq* avoids enqueuing jobs
78+
at the top of a second when the world is generally slightly busier.
79+
6480
Multiple Queues
6581
...............
6682

0 commit comments

Comments
 (0)