Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: allow uses to disable broker heartbeats by not providing a timeout (#1997,#1998) #2016

Merged
merged 2 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions kombu/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ def consume(self, limit=None, timeout=None, safety_interval=1, **kwargs):
try:
conn.drain_events(timeout=safety_interval)
except socket.timeout:
conn.heartbeat_check()
elapsed += safety_interval
if timeout and elapsed >= timeout:
raise
if timeout:
conn.heartbeat_check()
elapsed += safety_interval
if elapsed >= timeout:
raise
except OSError:
if not self.should_stop:
raise
Expand Down
20 changes: 20 additions & 0 deletions t/unit/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ def se(*args, **kwargs):
c.connection.drain_events.side_effect = se
with pytest.raises(socket.error):
next(it)
c.connection.heartbeat_check.assert_called()

def test_consume_drain_no_heartbeat_check(self):
c, Acons, Bcons = self._context()
c.should_stop = False
it = c.consume(no_ack=True, timeout=None)

def se(*args, **kwargs):
c.should_stop = True
raise socket.timeout()
c.connection.drain_events.side_effect = se
with pytest.raises(StopIteration):
next(it)
c.connection.heartbeat_check.assert_not_called()

it = c.consume(no_ack=True, timeout=0)
c.connection.drain_events.side_effect = se
with pytest.raises(StopIteration):
next(it)
c.connection.heartbeat_check.assert_not_called()

def test_Consumer_context(self):
c, Acons, Bcons = self._context()
Expand Down