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

fix: add a callback function on flush_rows #796

Merged
merged 6 commits into from
Jun 8, 2023
Merged
Changes from 1 commit
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: 9 additions & 0 deletions google/cloud/bigtable/batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ class MutationsBatcher(object):
:type flush_interval: float
:param flush_interval: (Optional) The interval (in seconds) between asynchronous flush.
Default is 1 second.

:type flush_completed_callback: Callable = None
:param flush_completed_callback: (Optional) A callable funtion for handling responses
mutianf marked this conversation as resolved.
Show resolved Hide resolved
after the request is flushed.
"""

def __init__(
Expand All @@ -200,6 +204,7 @@ def __init__(
flush_count=FLUSH_COUNT,
max_row_bytes=MAX_MUTATION_SIZE,
flush_interval=1,
flush_completed_callback=None,
):
self._rows = _MutationsBatchQueue(
max_mutation_bytes=max_row_bytes, flush_count=flush_count
Expand All @@ -215,6 +220,7 @@ def __init__(
)
self.futures_mapping = {}
self.exceptions = queue.Queue()
self.flush_completed_callback = flush_completed_callback
mutianf marked this conversation as resolved.
Show resolved Hide resolved

@property
def flush_count(self):
Expand Down Expand Up @@ -357,6 +363,9 @@ def _flush_rows(self, rows_to_flush):
if len(rows_to_flush) > 0:
response = self.table.mutate_rows(rows_to_flush)

if self.flush_completed_callback:
self.flush(response)
mutianf marked this conversation as resolved.
Show resolved Hide resolved

for result in response:
if result.code != 0:
exc = from_grpc_status(result.code, result.message)
Expand Down