Skip to content

Commit c0c232e

Browse files
committed
adding 'shadow_kwargs' method
1 parent 66bc17e commit c0c232e

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

HISTORY.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
History
44
-------
55

6+
v0.5.2 (2017-02-25)
7+
...................
8+
* add ``shadow_kwargs`` method to ``BaseWorker`` to make customising actors easier.
9+
610
v0.5.1 (2017-02-25)
711
...................
812
* reimplement worker reuse as it turned out to be useful in tests.
@@ -14,7 +18,7 @@ v0.5.0 (2017-02-20)
1418

1519
v0.4.1 (2017-02-11)
1620
...................
17-
* fix issue with ``Concurrent`` class binding with multiple actor instances
21+
* fix issue with ``Concurrent`` class binding with multiple actor instances.
1822

1923
v0.4.0 (2017-02-10)
2024
...................

arq/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__all__ = ['VERSION']
44

5-
VERSION = StrictVersion('0.5.1')
5+
VERSION = StrictVersion('0.5.2')

arq/worker.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,24 @@ async def shadow_factory(self) -> list:
106106
"""
107107
if self.shadows is None:
108108
raise TypeError('shadows not defined on worker')
109-
rp = await self.get_redis_pool()
110-
shadows = [s(redis_settings=self.redis_settings, is_shadow=True, loop=self.loop, existing_pool=rp)
111-
for s in self.shadows]
109+
kwargs = await self.shadow_kwargs()
110+
shadows = [s(**kwargs) for s in self.shadows]
112111
await asyncio.gather(*[s.startup() for s in shadows], loop=self.loop)
113112
return shadows
114113

114+
async def shadow_kwargs(self):
115+
"""
116+
Prepare the keyword arguments for initialising all shadows.
117+
118+
Override to customise the kwargs used to initialise shadows.
119+
"""
120+
return dict(
121+
redis_settings=self.redis_settings,
122+
is_shadow=True,
123+
loop=self.loop,
124+
existing_pool=await self.get_redis_pool(),
125+
)
126+
115127
@classmethod
116128
def logging_config(cls, verbose) -> dict:
117129
"""
@@ -415,7 +427,7 @@ def start_worker(worker_path: str, worker_class: str, burst: bool, loop: asyncio
415427
"""
416428
worker_cls = import_string(worker_path, worker_class)
417429
worker = worker_cls(burst=burst, loop=loop)
418-
work_logger.info('Starting %s on worker process pid=%d', worker_cls.__name__, os.getpid())
430+
work_logger.info('Starting "%s" on pid=%d', worker_cls.__name__, os.getpid())
419431
try:
420432
worker.run_until_complete()
421433
except HandledExit:

0 commit comments

Comments
 (0)