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

Add flush method to AIOKafkaProducer #209

Merged
merged 4 commits into from
Aug 28, 2017
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
8 changes: 6 additions & 2 deletions aiokafka/message_accumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,17 @@ def set_api_version(self, api_version):
self._api_version = api_version

@asyncio.coroutine
def close(self):
self._closed = True
def flush(self):
# NOTE: we copy to avoid mutation during `yield from` below
for batches in list(self._batches.values()):
for batch in list(batches):
yield from batch.wait_deliver()

@asyncio.coroutine
def close(self):
self._closed = True
yield from self.flush()

@asyncio.coroutine
def add_message(self, tp, key, value, timeout, timestamp_ms=None):
""" Add message to batch by topic-partition
Expand Down
6 changes: 5 additions & 1 deletion aiokafka/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,17 @@ def start(self):
self._message_accumulator.set_api_version(self.client.api_version)
log.debug("Kafka producer started")

@asyncio.coroutine
def flush(self):
"""Wait untill all batches are Delivered and futures resolved"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*untill -> until please.

yield from self._message_accumulator.flush()

@asyncio.coroutine
def stop(self):
"""Flush all pending data and close all connections to kafka cluster"""
if self._closed:
return

# Wait untill all batches are Delivered and futures resolved
yield from self._message_accumulator.close()

if self._sender_task:
Expand Down