Skip to content

Instantly share code, notes, and snippets.

@richardgrantserverless
Created May 31, 2022 21:57
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 richardgrantserverless/c58b8c357c4a254850742086ef32e0ba to your computer and use it in GitHub Desktop.
Save richardgrantserverless/c58b8c357c4a254850742086ef32e0ba to your computer and use it in GitHub Desktop.
# reprocess.py
import json
import os
import boto3
from log import logger
from service import handle_record
queue_url = os.environ['DEAD_LETTER_QUEUE']
client = boto3.client('sqs')
while True:
resp = client.receive_messages(QueueUrl=queue_name)
messages = resp.get('Messages')
# If we didn't receive any messages, the queue is empty and we can stop.
if not messages:
break
for message in messages:
body = json.loads(message['Body'])
record = body['record']
try:
handle_record(record)
client.delete_message(
QueueUrl=queue_name,
ReceiptHandle=message.get('ReceiptHandle')
)
except Exception as e:
logger.error(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment