From f3340856a5fc7a479cef97f07a8a604b02410700 Mon Sep 17 00:00:00 2001 From: James Brown Date: Mon, 22 Aug 2022 22:57:46 +0000 Subject: [PATCH] address review feedback --- pystalk/pool.py | 11 +++++------ tests/integration/test_pool.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pystalk/pool.py b/pystalk/pool.py index 09edbd0..d50b41f 100644 --- a/pystalk/pool.py +++ b/pystalk/pool.py @@ -46,7 +46,7 @@ class ProductionPool(object): :param round_robin: If true, every insertion will go to a different server in the pool. If false, the server will only be changed when an exception occurs. :param backoff_time: Number of seconds after an error before a server will be reused - :param shuffle: Randomly shuffle clients at initialization + :param initial_shuffle: Randomly shuffle clients at initialization All clients should have a socket timeout set or else some errors will not be detected. @@ -57,12 +57,11 @@ class ProductionPool(object): beanstalkd servers, consider the `pystalkworker` project. """ def __init__(self, clients: List[BeanstalkClient], round_robin: bool = True, - backoff_time: float = 10.0, shuffle: bool = True): + backoff_time: float = 10.0, initial_shuffle: bool = True): if not clients: raise ValueError('Must pass at least one BeanstalkClient') - self._current_client_index = 0 client_records = [ClientRecord(c) for c in clients] - if shuffle: + if initial_shuffle: random.shuffle(client_records) self._clients = deque(client_records) self.current_tube: Optional[str] = None @@ -72,7 +71,7 @@ def __init__(self, clients: List[BeanstalkClient], round_robin: bool = True, @classmethod def from_uris(cls, uris: List[str], socket_timeout: float = None, auto_decode: bool = False, - round_robin: bool = True, backoff_time: float = 10.0, shuffle: bool = True): + round_robin: bool = True, backoff_time: float = 10.0, initial_shuffle: bool = True): """Construct a pool from a list of URIs. See `pystalk.client.Client.from_uri` for more information. :param uris: A list of URIs @@ -84,7 +83,7 @@ def from_uris(cls, uris: List[str], socket_timeout: float = None, auto_decode: b for uri in uris], round_robin=round_robin, backoff_time=backoff_time, - shuffle=shuffle + initial_shuffle=initial_shuffle ) def use(self, tube: str): diff --git a/tests/integration/test_pool.py b/tests/integration/test_pool.py index ae29fdc..7324abb 100644 --- a/tests/integration/test_pool.py +++ b/tests/integration/test_pool.py @@ -28,7 +28,7 @@ def test_one_good_one_bad(tube_name, mocker, beanstalk_client, caplog): bad_client = mocker.Mock() bad_client.current_tube = tube_name bad_client.put_job_into.side_effect = BeanstalkError(b'INTERNAL_ERROR') - p = ProductionPool([bad_client, beanstalk_client], shuffle=False, backoff_time=10) + p = ProductionPool([bad_client, beanstalk_client], initial_shuffle=False, backoff_time=10) # put a job; this should try the bad tube, then the good tube and succeed with caplog.at_level(logging.WARNING): p.put_job_into(tube_name, b'job 1')