Skip to content

Commit

Permalink
Merge pull request #24 from ONSdigital/pubsub-check
Browse files Browse the repository at this point in the history
Use the recommended pattern of checking for failed publishing to pubsub
  • Loading branch information
Jamie authored May 28, 2019
2 parents 5a7ef7d + 0225066 commit f2a9e16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion test/component/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pika
from coverage.python import os
from google.api_core.exceptions import GoogleAPIError
from google.cloud import pubsub_v1


Expand Down Expand Up @@ -67,8 +68,12 @@ def publish_to_pubsub(self, tx_id, case_id, questionnaire_id):
eventType='OBJECT_FINALIZE',
bucketId='123',
objectId=tx_id)
while not future.done():
if not future.done():
time.sleep(1)
try:
future.result(timeout=30)
except GoogleAPIError:
assert False, "Failed to publish message to pubsub"

print(f'Message published to {topic_path}')

Expand Down
8 changes: 6 additions & 2 deletions test/scripts/publish_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import uuid

from google.api_core.exceptions import GoogleAPIError
from google.cloud import pubsub_v1


Expand All @@ -29,8 +30,11 @@
eventType='OBJECT_FINALIZE',
bucketId='123',
objectId=tx_id)

while not future.done():
if not future.done():
time.sleep(1)
try:
future.result(timeout=30)
except GoogleAPIError:
print("Failed to publish message to pubsub")

print(f'Message published to {topic_path}')

0 comments on commit f2a9e16

Please sign in to comment.