Skip to content

Commit 1d56a69

Browse files
authored
rename pole -> poll (#242)
* renme pole -> poll * tweak test
1 parent 0eaa748 commit 1d56a69

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

arq/jobs.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import logging
33
import pickle
4+
import warnings
45
from dataclasses import dataclass
56
from datetime import datetime
67
from enum import Enum
@@ -73,15 +74,24 @@ def __init__(
7374
self._queue_name = _queue_name
7475
self._deserializer = _deserializer
7576

76-
async def result(self, timeout: Optional[float] = None, *, pole_delay: float = 0.5) -> Any:
77+
async def result(
78+
self, timeout: Optional[float] = None, *, poll_delay: float = 0.5, pole_delay: float = None
79+
) -> Any:
7780
"""
7881
Get the result of the job, including waiting if it's not yet available. If the job raised an exception,
7982
it will be raised here.
8083
8184
:param timeout: maximum time to wait for the job result before raising ``TimeoutError``, will wait forever
82-
:param pole_delay: how often to poll redis for the job result
85+
:param poll_delay: how often to poll redis for the job result
86+
:param pole_delay: deprecated, use poll_delay instead
8387
"""
84-
async for delay in poll(pole_delay):
88+
if pole_delay is not None:
89+
warnings.warn(
90+
'"pole_delay" is deprecated, use the correct spelling "poll_delay" instead', DeprecationWarning
91+
)
92+
poll_delay = pole_delay
93+
94+
async for delay in poll(poll_delay):
8595
info = await self.result_info()
8696
if info:
8797
result = info.result
@@ -132,18 +142,18 @@ async def status(self) -> JobStatus:
132142
return JobStatus.not_found
133143
return JobStatus.deferred if score > timestamp_ms() else JobStatus.queued
134144

135-
async def abort(self, *, timeout: Optional[float] = None, pole_delay: float = 0.5) -> bool:
145+
async def abort(self, *, timeout: Optional[float] = None, poll_delay: float = 0.5) -> bool:
136146
"""
137147
Abort the job.
138148
139149
:param timeout: maximum time to wait for the job result before raising ``TimeoutError``,
140150
will wait forever on None
141-
:param pole_delay: how often to poll redis for the job result
151+
:param poll_delay: how often to poll redis for the job result
142152
:return: True if the job aborted properly, False otherwise
143153
"""
144154
await self._redis.zadd(abort_jobs_ss, timestamp_ms(), self.job_id)
145155
try:
146-
await self.result(timeout=timeout, pole_delay=pole_delay)
156+
await self.result(timeout=timeout, poll_delay=poll_delay)
147157
except asyncio.CancelledError:
148158
return True
149159
else:

tests/test_jobs.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def test_unknown(arq_redis: ArqRedis):
2727
async def test_result_timeout(arq_redis: ArqRedis):
2828
j = Job('foobar', arq_redis)
2929
with pytest.raises(asyncio.TimeoutError):
30-
await j.result(0.1, pole_delay=0)
30+
await j.result(0.1, poll_delay=0)
3131

3232

3333
async def test_enqueue_job(arq_redis: ArqRedis, worker, queue_name=default_queue_name):
@@ -39,7 +39,7 @@ async def foobar(ctx, *args, **kwargs):
3939
assert JobStatus.queued == await j.status()
4040
worker: Worker = worker(functions=[func(foobar, name='foobar')], queue_name=queue_name)
4141
await worker.main()
42-
r = await j.result(pole_delay=0)
42+
r = await j.result(poll_delay=0)
4343
assert r == 42
4444
assert JobStatus.complete == await j.status()
4545
info = await j.info()
@@ -138,13 +138,13 @@ async def foobar(ctx, a, b):
138138
assert JobStatus.queued == await j.status()
139139
worker: Worker = worker(functions=[func(foobar, name='foobar')])
140140
await worker.run_check()
141-
assert await j.result(pole_delay=0) == 3
142-
assert await j.result(pole_delay=0) == 3
141+
assert await j.result(poll_delay=0) == 3
142+
assert await j.result(poll_delay=0) == 3
143143
info = await j.info()
144144
assert info.args == (1, 2)
145145
await arq_redis.set(result_key_prefix + j.job_id, b'invalid pickle data')
146146
with pytest.raises(DeserializationError, match='unable to deserialize job result'):
147-
assert await j.result(pole_delay=0) == 3
147+
assert await j.result(poll_delay=0) == 3
148148

149149

150150
async def test_deserialize_info(arq_redis: ArqRedis):
@@ -165,3 +165,13 @@ async def test_deserialize_job_raw():
165165
async def test_get_job_result(arq_redis: ArqRedis):
166166
with pytest.raises(KeyError, match='job "foobar" not found'):
167167
await arq_redis._get_job_result('foobar')
168+
169+
170+
async def test_result_pole_delay_dep(arq_redis: ArqRedis):
171+
j = Job('foobar', arq_redis)
172+
r = serialize_result('foobar', (1,), {}, 1, 123, True, 42, 123, 123, 'testing', 'test-queue')
173+
await arq_redis.set(result_key_prefix + j.job_id, r)
174+
with pytest.warns(
175+
DeprecationWarning, match='"pole_delay" is deprecated, use the correct spelling "poll_delay" instead'
176+
):
177+
assert await j.result(pole_delay=0) == 42

tests/test_main.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def foobar(ctx):
2525
j = await arq_redis.enqueue_job('foobar')
2626
worker: Worker = worker(functions=[func(foobar, name='foobar')])
2727
await worker.main()
28-
r = await j.result(pole_delay=0)
28+
r = await j.result(poll_delay=0)
2929
assert r == 42 # 1
3030

3131

@@ -40,8 +40,8 @@ async def foobar(ctx):
4040

4141
await worker1.main()
4242
await worker2.main()
43-
r1 = await j1.result(pole_delay=0)
44-
r2 = await j2.result(pole_delay=0)
43+
r1 = await j1.result(poll_delay=0)
44+
r2 = await j2.result(poll_delay=0)
4545
assert r1 == 42 # 1
4646
assert r2 == 42 # 2
4747

@@ -58,10 +58,10 @@ async def parent_job(ctx):
5858
worker: Worker = worker(functions=[func(parent_job, name='parent_job'), func(foobar, name='foobar')])
5959

6060
await worker.main()
61-
result = await job.result(pole_delay=0)
61+
result = await job.result(poll_delay=0)
6262
assert result is not None
6363
inner_job = Job(result, arq_redis)
64-
inner_result = await inner_job.result(pole_delay=0)
64+
inner_result = await inner_job.result(poll_delay=0)
6565
assert inner_result == 42
6666

6767

@@ -83,10 +83,10 @@ async def parent_job(ctx):
8383
)
8484

8585
await worker.main()
86-
result = await job.result(pole_delay=0)
86+
result = await job.result(poll_delay=0)
8787
assert result is not None
8888
inner_job = Job(result, arq_redis_msgpack, _deserializer=functools.partial(msgpack.unpackb, raw=False))
89-
inner_result = await inner_job.result(pole_delay=0)
89+
inner_result = await inner_job.result(poll_delay=0)
9090
assert inner_result == 42
9191

9292

@@ -107,10 +107,10 @@ async def parent_job(ctx):
107107
)
108108

109109
await worker.main()
110-
inner_job_id = await job.result(pole_delay=0)
110+
inner_job_id = await job.result(poll_delay=0)
111111
assert inner_job_id is not None
112112
inner_job = Job(inner_job_id, arq_redis, _queue_name='spanner')
113-
inner_result = await inner_job.result(pole_delay=0)
113+
inner_result = await inner_job.result(poll_delay=0)
114114
assert inner_result == 42
115115

116116

@@ -123,7 +123,7 @@ async def foobar(ctx):
123123
await worker.main()
124124

125125
with pytest.raises(RuntimeError, match='foobar error'):
126-
await j.result(pole_delay=0)
126+
await j.result(poll_delay=0)
127127

128128

129129
async def test_job_info(arq_redis: ArqRedis):
@@ -190,12 +190,12 @@ async def foobar(ctx):
190190
j1 = await arq_redis.enqueue_job('foobar')
191191
w: Worker = worker(functions=[func(foobar, name='foobar')])
192192
await w.main()
193-
r = await j1.result(pole_delay=0)
193+
r = await j1.result(poll_delay=0)
194194
assert r == 1
195195

196196
j2 = await arq_redis.enqueue_job('foobar', _job_try=3)
197197
await w.main()
198-
r = await j2.result(pole_delay=0)
198+
r = await j2.result(poll_delay=0)
199199
assert r == 3
200200

201201

@@ -208,7 +208,7 @@ async def foobar(ctx):
208208
j1 = await arq_redis.enqueue_job('foobar', _job_try=3)
209209
w: Worker = worker(functions=[func(foobar, name='foobar')])
210210
await w.main()
211-
r = await j1.result(pole_delay=0)
211+
r = await j1.result(poll_delay=0)
212212
assert r == 4
213213

214214

@@ -233,7 +233,7 @@ async def foobar(ctx):
233233
w: Worker = worker(functions=[func(foobar, name='foobar')])
234234
await w.main()
235235
with pytest.raises(SerializationError, match='unable to serialize result'):
236-
await j1.result(pole_delay=0)
236+
await j1.result(poll_delay=0)
237237

238238

239239
async def test_get_jobs(arq_redis: ArqRedis):

tests/test_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ async def return_error(ctx):
489489
worker: Worker = worker(functions=[func(return_error, name='return_error')])
490490
await worker.main()
491491
assert (worker.jobs_complete, worker.jobs_failed, worker.jobs_retried) == (1, 0, 0)
492-
r = await j.result(pole_delay=0)
492+
r = await j.result(poll_delay=0)
493493
assert isinstance(r, TypeError)
494494
info = await j.result_info()
495495
assert info.success is True

0 commit comments

Comments
 (0)