Skip to content

chunking publish to pubsub #11

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

Merged
merged 5 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion README_CONTAINER_REGISTRY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BITCOINETL_STREAMING_VERSION=1.4-streaming
BITCOINETL_STREAMING_VERSION=1.4-chunk-streaming
docker build -t merklescience/bitcoin-etl:${BITCOINETL_STREAMING_VERSION} -f Dockerfile_with_streaming .
docker tag merklescience/bitcoin-etl:${BITCOINETL_STREAMING_VERSION} us.gcr.io/staging-btc-etl/merklescience/bitcoin-etl:${BITCOINETL_STREAMING_VERSION}
docker push us.gcr.io/staging-btc-etl/merklescience/bitcoin-etl:${BITCOINETL_STREAMING_VERSION}
Expand Down
25 changes: 15 additions & 10 deletions blockchainetl/jobs/exporters/google_pubsub_item_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,21 @@ def open(self):
pass

def export_items(self, items):
try:
self._export_items_with_timeout(items)
except timeout_decorator.TimeoutError as e:
# A bug in PubSub publisher that makes it stalled after running for some time.
# Exception in thread Thread-CommitBatchPublisher:
# details = "channel is in state TRANSIENT_FAILURE"
# https://stackoverflow.com/questions/55552606/how-can-one-catch-exceptions-in-python-pubsub-subscriber-that-are-happening-in-i?noredirect=1#comment97849067_55552606
logging.info('Recreating Pub/Sub publisher.')
self.publisher = self.create_publisher()
raise e
tot_steps = (len(items) // 1000) + 1
logging.info('Total publish loop steps'+str(tot_steps))
for i in range(0, len(items), 1000):
mini_batch = items[i:i + 1000]
logging.info('Current Loop Iteration' + str(i + 1)+ 'out of'+str(tot_steps))
try:
self._export_items_with_timeout(mini_batch)
except timeout_decorator.TimeoutError as e:
# A bug in PubSub publisher that makes it stalled after running for some time.
# Exception in thread Thread-CommitBatchPublisher:
# details = "channel is in state TRANSIENT_FAILURE"
# https://stackoverflow.com/questions/55552606/how-can-one-catch-exceptions-in-python-pubsub-subscriber-that-are-happening-in-i?noredirect=1#comment97849067_55552606
logging.info('Recreating Pub/Sub publisher.')
self.publisher = self.create_publisher()
raise e

@timeout_decorator.timeout(300)
def _export_items_with_timeout(self, items):
Expand Down