-
-
Save richardgrantserverless/c58b8c357c4a254850742086ef32e0ba 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
# 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