Korrekturen
This commit is contained in:
parent
dc57e08030
commit
4943bccb3e
|
|
@ -19,20 +19,22 @@ MAX_EMAIL_SIZE = int(os.environ.get('MAX_EMAIL_SIZE', '10485760'))
|
||||||
s3_client = boto3.client('s3')
|
s3_client = boto3.client('s3')
|
||||||
|
|
||||||
def mark_email_processed(bucket, key, s3_client, processor='lambda'):
|
def mark_email_processed(bucket, key, s3_client, processor='lambda'):
|
||||||
"""Setzt in S3 das processed-Flag per Metadata."""
|
try:
|
||||||
s3_client.copy_object(
|
s3_client.copy_object(
|
||||||
Bucket=bucket,
|
Bucket=bucket,
|
||||||
Key=key,
|
Key=key,
|
||||||
CopySource={'Bucket': bucket, 'Key': key},
|
CopySource={'Bucket': bucket, 'Key': key},
|
||||||
Metadata={
|
Metadata={
|
||||||
'processed': 'true',
|
'processed': 'true',
|
||||||
'processed_timestamp': str(int(time.time())),
|
'processed_timestamp': str(int(time.time())),
|
||||||
'processor': processor
|
'processor': processor
|
||||||
},
|
},
|
||||||
MetadataDirective='REPLACE'
|
MetadataDirective='REPLACE'
|
||||||
)
|
)
|
||||||
logger.info(f"Marked S3 object {bucket}/{key} as processed")
|
logger.info(f"Marked S3 object {bucket}/{key} as processed")
|
||||||
|
except botocore.exceptions.ClientError as e:
|
||||||
|
logger.error(f"Fehler beim Markieren {bucket}/{key}: {e}")
|
||||||
|
|
||||||
def call_api_once(payload, domain, request_id):
|
def call_api_once(payload, domain, request_id):
|
||||||
"""Single-shot POST, kein Retry."""
|
"""Single-shot POST, kein Retry."""
|
||||||
url = f"{API_BASE_URL}/process/{domain}"
|
url = f"{API_BASE_URL}/process/{domain}"
|
||||||
|
|
@ -64,6 +66,12 @@ def lambda_handler(event, context):
|
||||||
|
|
||||||
# Kopf-Check
|
# Kopf-Check
|
||||||
head = s3_client.head_object(Bucket=bucket, Key=key)
|
head = s3_client.head_object(Bucket=bucket, Key=key)
|
||||||
|
|
||||||
|
metadata = head.get('Metadata', {})
|
||||||
|
if metadata.get('processed') == 'true':
|
||||||
|
logger.info(f"[{req_id}] Skipping already processed object")
|
||||||
|
return {'statusCode': 200, 'body': 'Already processed'}
|
||||||
|
|
||||||
size = head['ContentLength']
|
size = head['ContentLength']
|
||||||
if size > MAX_EMAIL_SIZE:
|
if size > MAX_EMAIL_SIZE:
|
||||||
logger.warning(f"[{req_id}] Email too large: {size} bytes")
|
logger.warning(f"[{req_id}] Email too large: {size} bytes")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue