forked from python-arq/arq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
36 lines (27 loc) · 841 Bytes
/
Copy pathexample.py
File metadata and controls
36 lines (27 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from arq import Actor, BaseWorker, concurrent
class ActorTest(Actor):
@concurrent
async def foo(self, a, b=0):
with open('foo', 'w') as f:
r = a + b
f.write('{}'.format(r))
class Worker(BaseWorker):
signature = 'foobar'
shadows = [ActorTest]
class WorkerSignalQuit(Worker):
"""
worker which simulates receiving sigint after 2 jobs
"""
max_concurrent_tasks = 1
async def run_job(self, *args):
await super().run_job(*args)
if self.jobs_complete >= 2:
self.handle_sig(2)
class WorkerSignalTwiceQuit(Worker):
"""
worker which simulates receiving sigint twice after 2 jobs
"""
async def run_job(self, *args):
await super().run_job(*args)
if self.jobs_complete >= 2:
self.handle_sig_force(2, None)