mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
Merge pull request #978 from Hestia-Homes/main
Some checks failed
Fast Api Backend Deploy / deploy (push) Has been cancelled
Deploy infrastructure / determine_stage (push) Has been cancelled
Deploy infrastructure / ara_engine_image (push) Has been cancelled
Deploy infrastructure / ara_engine_lambda (push) Has been cancelled
Deploy infrastructure / shared_terraform (push) Has been cancelled
Deploy infrastructure / address2uprn_image (push) Has been cancelled
Deploy infrastructure / address2uprn_lambda (push) Has been cancelled
Deploy infrastructure / postcodeSplitter_image (push) Has been cancelled
Deploy infrastructure / postcodeSplitter_lambda (push) Has been cancelled
Deploy infrastructure / condition_etl_image (push) Has been cancelled
Deploy infrastructure / condition_etl_lambda (push) Has been cancelled
Deploy infrastructure / categorisation_image (push) Has been cancelled
Deploy infrastructure / categorisation_lambda (push) Has been cancelled
Deploy infrastructure / ordnanceSurvey_image (push) Has been cancelled
Deploy infrastructure / ordnanceSurvey_lambda (push) Has been cancelled
Deploy infrastructure / pashub_to_ara_image (push) Has been cancelled
Deploy infrastructure / pashub_to_ara_lambda (push) Has been cancelled
Deploy infrastructure / fast_api_lambda (push) Has been cancelled
Deploy infrastructure / cloudfront_acm (push) Has been cancelled
Deploy infrastructure / cloudfront_cdn (push) Has been cancelled
Deploy infrastructure / hubspot_etl_image (push) Has been cancelled
Deploy infrastructure / hubspot_etl_lambda (push) Has been cancelled
Some checks failed
Fast Api Backend Deploy / deploy (push) Has been cancelled
Deploy infrastructure / determine_stage (push) Has been cancelled
Deploy infrastructure / ara_engine_image (push) Has been cancelled
Deploy infrastructure / ara_engine_lambda (push) Has been cancelled
Deploy infrastructure / shared_terraform (push) Has been cancelled
Deploy infrastructure / address2uprn_image (push) Has been cancelled
Deploy infrastructure / address2uprn_lambda (push) Has been cancelled
Deploy infrastructure / postcodeSplitter_image (push) Has been cancelled
Deploy infrastructure / postcodeSplitter_lambda (push) Has been cancelled
Deploy infrastructure / condition_etl_image (push) Has been cancelled
Deploy infrastructure / condition_etl_lambda (push) Has been cancelled
Deploy infrastructure / categorisation_image (push) Has been cancelled
Deploy infrastructure / categorisation_lambda (push) Has been cancelled
Deploy infrastructure / ordnanceSurvey_image (push) Has been cancelled
Deploy infrastructure / ordnanceSurvey_lambda (push) Has been cancelled
Deploy infrastructure / pashub_to_ara_image (push) Has been cancelled
Deploy infrastructure / pashub_to_ara_lambda (push) Has been cancelled
Deploy infrastructure / fast_api_lambda (push) Has been cancelled
Deploy infrastructure / cloudfront_acm (push) Has been cancelled
Deploy infrastructure / cloudfront_cdn (push) Has been cancelled
Deploy infrastructure / hubspot_etl_image (push) Has been cancelled
Deploy infrastructure / hubspot_etl_lambda (push) Has been cancelled
Ensure all events in task handler are processed
This commit is contained in:
commit
9a1eb202e3
1 changed files with 50 additions and 33 deletions
|
|
@ -113,12 +113,17 @@ def task_handler():
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(event: dict[str, Any], context: Any, *args, **kwargs):
|
def wrapper(event: dict[str, Any], context: Any, *args, **kwargs):
|
||||||
|
|
||||||
logger = setup_logger()
|
logger = setup_logger()
|
||||||
|
|
||||||
# Parse body: Records-style SQS or plain dict event
|
records = event.get("Records", [event]) # fallback for non-SQS
|
||||||
if "Records" in event:
|
|
||||||
raw_body = event["Records"][0].get("body", {})
|
results = []
|
||||||
|
failures = []
|
||||||
|
|
||||||
|
for record in records:
|
||||||
|
# Parse body
|
||||||
|
raw_body = record.get("body", record)
|
||||||
|
|
||||||
if isinstance(raw_body, str):
|
if isinstance(raw_body, str):
|
||||||
try:
|
try:
|
||||||
body = json.loads(raw_body)
|
body = json.loads(raw_body)
|
||||||
|
|
@ -126,43 +131,55 @@ def task_handler():
|
||||||
body = {}
|
body = {}
|
||||||
else:
|
else:
|
||||||
body = raw_body or {}
|
body = raw_body or {}
|
||||||
else:
|
|
||||||
body = event
|
|
||||||
|
|
||||||
# Create fresh task + subtask
|
# Create task per message
|
||||||
logger.info("Creating task for source: %s", task_source)
|
logger.info("Creating task for source: %s", task_source)
|
||||||
task_id, subtask_id = TasksInterface.create_task(
|
task_id, subtask_id = TasksInterface.create_task(
|
||||||
task_source=task_source,
|
task_source=task_source,
|
||||||
inputs=body,
|
inputs=body,
|
||||||
)
|
)
|
||||||
logger.info("Created task_id=%s subtask_id=%s", task_id, subtask_id)
|
|
||||||
|
|
||||||
interface = SubTaskInterface()
|
logger.info("Created task_id=%s subtask_id=%s", task_id, subtask_id)
|
||||||
|
|
||||||
interface.update_subtask_status(
|
interface = SubTaskInterface()
|
||||||
subtask_id=subtask_id,
|
|
||||||
status="in progress",
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
result = func(body, context, *args, **kwargs)
|
|
||||||
|
|
||||||
interface.update_subtask_status(
|
interface.update_subtask_status(
|
||||||
subtask_id=subtask_id,
|
subtask_id=subtask_id,
|
||||||
status="complete",
|
status="in progress",
|
||||||
outputs={"result": result} if result else None,
|
|
||||||
)
|
)
|
||||||
logger.info("Task %s completed successfully", task_id)
|
|
||||||
return result
|
|
||||||
|
|
||||||
except Exception as e:
|
try:
|
||||||
logger.exception("Task %s failed: %s", task_id, e)
|
result = func(body, context, *args, **kwargs)
|
||||||
interface.update_subtask_status(
|
|
||||||
subtask_id=subtask_id,
|
interface.update_subtask_status(
|
||||||
status="failed",
|
subtask_id=subtask_id,
|
||||||
outputs={"error": str(e)},
|
status="complete",
|
||||||
)
|
outputs={"result": result} if result else None,
|
||||||
raise
|
)
|
||||||
|
|
||||||
|
logger.info("Task %s completed successfully", task_id)
|
||||||
|
results.append(result)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception("Task %s failed: %s", task_id, e)
|
||||||
|
|
||||||
|
interface.update_subtask_status(
|
||||||
|
subtask_id=subtask_id,
|
||||||
|
status="failed",
|
||||||
|
outputs={"error": str(e)},
|
||||||
|
)
|
||||||
|
|
||||||
|
if "Records" in event:
|
||||||
|
failures.append({"itemIdentifier": record["messageId"]})
|
||||||
|
else:
|
||||||
|
# Handle non-SQS events
|
||||||
|
raise
|
||||||
|
|
||||||
|
if "Records" in event:
|
||||||
|
return {"batchItemFailures": failures}
|
||||||
|
|
||||||
|
# Handle non-SQS events
|
||||||
|
return results
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue