Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Roguelazer committed Aug 22, 2022
1 parent 3bc053e commit f334085
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions pystalk/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit f334085

Please sign in to comment.