Skip to content

Instantly share code, notes, and snippets.

@shar1z
Created August 1, 2022 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shar1z/2990f8f59104cbea812e0cb16d870dd6 to your computer and use it in GitHub Desktop.
Save shar1z/2990f8f59104cbea812e0cb16d870dd6 to your computer and use it in GitHub Desktop.
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