Retry-Logik

This commit is contained in:
Andreas Knuth 2025-12-23 17:05:30 -06:00
parent 05f4a38eb6
commit cd91418def
1 changed files with 34 additions and 19 deletions

View File

@ -59,30 +59,45 @@ def is_ses_bounce_notification(parsed):
return 'mailer-daemon@us-east-2.amazonses.com' in from_h return 'mailer-daemon@us-east-2.amazonses.com' in from_h
def get_bounce_info_from_dynamodb(message_id): def get_bounce_info_from_dynamodb(message_id, max_retries=3, retry_delay=1):
""" """
Sucht Bounce-Info in DynamoDB anhand der Message-ID Sucht Bounce-Info in DynamoDB anhand der Message-ID
Mit Retry-Logik für Timing-Issues
Returns: dict mit bounce info oder None Returns: dict mit bounce info oder None
""" """
try: import time
response = msg_table.get_item(Key={'MessageId': message_id})
item = response.get('Item')
if not item: for attempt in range(max_retries):
log(f"⚠ No bounce record found for Message-ID: {message_id}") try:
return None response = msg_table.get_item(Key={'MessageId': message_id})
item = response.get('Item')
return { if item:
'original_source': item.get('original_source', ''), # Gefunden!
'bounceType': item.get('bounceType', 'Unknown'), return {
'bounceSubType': item.get('bounceSubType', 'Unknown'), 'original_source': item.get('original_source', ''),
'bouncedRecipients': item.get('bouncedRecipients', []), 'bounceType': item.get('bounceType', 'Unknown'),
'timestamp': item.get('timestamp', '') 'bounceSubType': item.get('bounceSubType', 'Unknown'),
} 'bouncedRecipients': item.get('bouncedRecipients', []),
'timestamp': item.get('timestamp', '')
}
except Exception as e: # Nicht gefunden - Retry falls nicht letzter Versuch
log(f"⚠ DynamoDB Error: {e}", 'ERROR') if attempt < max_retries - 1:
return None log(f" Bounce record not found yet, retrying in {retry_delay}s (attempt {attempt + 1}/{max_retries})...")
time.sleep(retry_delay)
else:
log(f"⚠ No bounce record found after {max_retries} attempts for Message-ID: {message_id}")
return None
except Exception as e:
log(f"⚠ DynamoDB Error (attempt {attempt + 1}/{max_retries}): {e}", 'ERROR')
if attempt < max_retries - 1:
time.sleep(retry_delay)
else:
return None
return None
def apply_bounce_logic(parsed, subject): def apply_bounce_logic(parsed, subject):