logging
This commit is contained in:
parent
fc6fa76bc0
commit
26adce6ecf
|
|
@ -52,6 +52,8 @@ def mark_email_as_processed(bucket, key):
|
|||
|
||||
@app.route('/process/<domain>', methods=['POST'])
|
||||
def process_email(domain):
|
||||
logger.info(f"[{request_id}] INCOMING POST /process/{domain}: "
|
||||
f"payload_keys={list(data.keys())}")
|
||||
auth = request.headers.get('Authorization')
|
||||
if auth != f'Bearer {API_TOKEN}':
|
||||
return jsonify({'error': 'Unauthorized'}), 401
|
||||
|
|
@ -67,6 +69,7 @@ def process_email(domain):
|
|||
|
||||
msg = BytesParser(policy=default).parsebytes(email_bytes)
|
||||
from_addr = getaddresses(msg.get_all('from', []))[0][1] if msg.get_all('from') else f'lambda@{domain}'
|
||||
logger.debug(f"[{request_id}] Parsed email: from={from_addr}, recipients={recipients}")
|
||||
recipients = []
|
||||
for hdr in ('to', 'cc', 'bcc'):
|
||||
recipients += [addr for _n, addr in getaddresses(msg.get_all(hdr, []))]
|
||||
|
|
@ -95,6 +98,8 @@ def retry_domain_emails(domain):
|
|||
if head.get('Metadata', {}).get('processed') != 'true':
|
||||
unprocessed.append(obj['Key'])
|
||||
|
||||
logger.info(f"[{request_id}] RETRY processing for domain={domain}, keys={unprocessed}")
|
||||
|
||||
results = {'processed': [], 'failed': []}
|
||||
for key in unprocessed:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ def call_api_with_retry(payload, domain, request_id, max_retries=3):
|
|||
payload_json = json.dumps(payload).encode('utf-8')
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
logger.info(f"[{request_id}] Attempt {attempt+1}: POST payload to {sync_url}")
|
||||
req = urllib.request.Request(sync_url, data=payload_json, method="POST")
|
||||
req.add_header('Authorization', f'Bearer {API_TOKEN}')
|
||||
req.add_header('Content-Type', 'application/json')
|
||||
|
|
@ -65,6 +66,7 @@ def call_api_with_retry(payload, domain, request_id, max_retries=3):
|
|||
with urllib.request.urlopen(req, timeout=timeout, context=context) as response:
|
||||
code = response.getcode()
|
||||
if code == 200:
|
||||
logger.info(f"[{request_id}] API response: {response_code}")
|
||||
return True
|
||||
except urllib.error.HTTPError as e:
|
||||
if 400 <= e.code < 500:
|
||||
|
|
@ -114,6 +116,10 @@ def lambda_handler(event, context):
|
|||
'compressed_size': len(compressed)
|
||||
}
|
||||
|
||||
logger.info(f"[{request_id}] OUTGOING payload to {API_BASE_URL}/process/{domain}: "
|
||||
f"domain={domain}, key={key}, bucket={bucket}, "
|
||||
f"orig_size={len(body)}, comp_size={len(compressed)}")
|
||||
|
||||
if call_api_with_retry(payload, domain, request_id):
|
||||
# Inline metadata marking statt Löschung
|
||||
mark_email_processed(bucket, key)
|
||||
|
|
|
|||
Loading…
Reference in New Issue