Created
August 1, 2022 10:10
-
-
Save shar1z/2990f8f59104cbea812e0cb16d870dd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _handle_event(event_detail_type: str, event_detail: dict) -> None: | |
try: | |
handle_task(event_detail_type, event) | |
except ExecutionSyncError: # Raised if this is a "task_completed" event, and "task_started" hasn't arrive yet | |
if event.retry_count < MAX_RETRY_COUNT: | |
logger.info('Events are not in sync, sending this event to the retry queue ' | |
f'(retry_count={event.retry_count})') | |
event.retry_count += 1 | |
message = { | |
DETAIL_TYPE: event_detail_type, | |
DETAIL: event.dict() | |
} | |
sqs = SQSClient(TASKS_QUEUE_NAME) | |
sqs.send_message(message, delay_seconds=DELAY_SECONDS) # Messages in the queue are delayed | |
else: | |
logger.info('Events are not in sync and max retry count reached. Failing') | |
raise # Will be handled by the @exception_handler decorator which wraps handler() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment