Retry-Logik
This commit is contained in:
parent
05f4a38eb6
commit
cd91418def
53
worker.py
53
worker.py
|
|
@ -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:
|
|
||||||
log(f"⚠ No bounce record found for Message-ID: {message_id}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
return {
|
|
||||||
'original_source': item.get('original_source', ''),
|
|
||||||
'bounceType': item.get('bounceType', 'Unknown'),
|
|
||||||
'bounceSubType': item.get('bounceSubType', 'Unknown'),
|
|
||||||
'bouncedRecipients': item.get('bouncedRecipients', []),
|
|
||||||
'timestamp': item.get('timestamp', '')
|
|
||||||
}
|
|
||||||
|
|
||||||
except Exception as e:
|
for attempt in range(max_retries):
|
||||||
log(f"⚠ DynamoDB Error: {e}", 'ERROR')
|
try:
|
||||||
return None
|
response = msg_table.get_item(Key={'MessageId': message_id})
|
||||||
|
item = response.get('Item')
|
||||||
|
|
||||||
|
if item:
|
||||||
|
# Gefunden!
|
||||||
|
return {
|
||||||
|
'original_source': item.get('original_source', ''),
|
||||||
|
'bounceType': item.get('bounceType', 'Unknown'),
|
||||||
|
'bounceSubType': item.get('bounceSubType', 'Unknown'),
|
||||||
|
'bouncedRecipients': item.get('bouncedRecipients', []),
|
||||||
|
'timestamp': item.get('timestamp', '')
|
||||||
|
}
|
||||||
|
|
||||||
|
# Nicht gefunden - Retry falls nicht letzter Versuch
|
||||||
|
if attempt < max_retries - 1:
|
||||||
|
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):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue