@@ -6,7 +6,7 @@ Usage is best described by example.
6
6
Simple Usage
7
7
............
8
8
9
- .. literalinclude :: demo .py
9
+ .. literalinclude :: examples/main_demo .py
10
10
11
11
(This script is complete, it should run "as is" both to enqueue jobs and run them)
12
12
@@ -67,18 +67,7 @@ Multiple Queues
67
67
Functions can be assigned to different queues, by default arq defines three queues:
68
68
``HIGH_QUEUE ``, ``DEFAULT_QUEUE `` and ``LOW_QUEUE `` which are prioritised by the worker in that order.
69
69
70
- .. code :: python
71
-
72
- from arq import Actor, concurrent
73
-
74
- class RegistrationEmail (Actor ):
75
- @concurrent
76
- async def email_standard_user (self , user_id ):
77
- send_user_email(user_id)
78
-
79
- @concurrent (Actor.HIGH_QUEUE )
80
- async def email_premium_user (self , user_id ):
81
- send_user_email(user_id)
70
+ .. literalinclude :: examples/multiple_queues.py
82
71
83
72
(Just a snippet, won't run "as is")
84
73
@@ -87,18 +76,7 @@ Direct Enqueuing
87
76
88
77
Functions can we enqueued directly whether or no they're decorated with ``@concurrent ``.
89
78
90
- .. code :: python
91
-
92
- from arq import Actor, concurrent
93
-
94
- class FooBar (Actor ):
95
- async def foo (self , a , b , c ):
96
- print (a + b + c)
97
-
98
- async def main ():
99
- foobar = FooBar()
100
- await foobar.enqueue_job(' foo' , 1 , 2 , c = 48 , queue = Actor.LOW_QUEUE )
101
- await foobar.enqueue_job(' foo' , 1 , 2 , c = 48 ) # this will be queued in DEFAULT_QUEUE
79
+ .. literalinclude :: examples/direct_enqueuing.py
102
80
103
81
104
82
(This script is almost complete except for ``loop.run_until_complete(main()) `` as above to run ``main ``,
@@ -112,31 +90,7 @@ Worker Customisation
112
90
Workers can be customised in numerous ways, this is preferred to command line arguments as it's easier to
113
91
document and record.
114
92
115
- .. code :: python
116
-
117
- from arq import BaseWorker
118
-
119
- class Worker (BaseWorker ):
120
- # execute jobs from both Downloader and FooBar above
121
- shadows = [Downloader, FooBar]
122
-
123
- # allow lots and lots of jobs to run simultaniously, default 50
124
- max_concurrent_tasks = 500
125
-
126
- # force the worker to close quickly after a termination signal is received, default 6
127
- shutdown_delay = 2
128
-
129
- # jobs may not take more than 10 seconds, default 60
130
- timeout_seconds = 10
131
-
132
- # number of seconds between health checks, default 60
133
- health_check_interval = 30
134
-
135
- def logging_config (self , verbose ):
136
- conf = super ().logging_config(verbose)
137
- # alter logging setup to set arq.jobs level to WARNING
138
- conf[' loggers' ][' arq.jobs' ][' level' ] = ' WARNING'
139
- return conf
93
+ .. literalinclude :: examples/worker_customisation.py
140
94
141
95
(This script is more-or-less complete,
142
96
provided ``Downloader `` and ``FooBar `` are defined and imported it should run "as is")
0 commit comments