Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ def load(self):
if self._leaser is None:
return 0

messages_percent = self._leaser.message_count / self._flow_control.max_messages
bytes_percent = self._leaser.bytes / self._flow_control.max_bytes
print(f"{messages_percent}, {bytes_percent}")
return max(messages_percent, bytes_percent)
return max(
[
self._leaser.message_count / self._flow_control.max_messages,
self._leaser.bytes / self._flow_control.max_bytes,
]
)

def add_close_callback(self, callback):
"""Schedules a callable when the manager closes.
Expand All @@ -208,12 +210,10 @@ def add_close_callback(self, callback):

def maybe_pause_consumer(self):
"""Check the current load and pause the consumer if needed."""
print(self.load)
if self.load >= 1.0:
if self._consumer is not None and not self._consumer.is_paused:
_LOGGER.debug("Message backlog over load at %.2f, pausing.", self.load)
self._consumer.pause()
print('paused')

def maybe_resume_consumer(self):
"""Check the current load and resume the consumer if needed."""
Expand All @@ -227,7 +227,6 @@ def maybe_resume_consumer(self):
return

if self.load < self.flow_control.resume_threshold:
print('resuming')
self._consumer.resume()
else:
_LOGGER.debug("Did not resume, current load is %s", self.load)
Expand Down
1 change: 1 addition & 0 deletions pubsub/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def cleanup():
for to_call, argument in registry:
to_call(argument)


def test_publish_messages(publisher, topic_path, cleanup):
futures = []
# Make sure the topic gets deleted.
Expand Down