feat: Add logging utility for calendar sync operations and enhance error handling

This commit is contained in:
bsiggel
2026-03-12 19:26:04 +00:00
parent 9bbfa61b3b
commit 8ed7cca432
6 changed files with 630 additions and 12 deletions

View File

@@ -1056,6 +1056,11 @@ async def handler(input_data: Dict[str, Any], ctx: FlowContext) -> None:
return {'status': 200, 'body': {'status': 'completed', 'kuerzel': kuerzel}}
except Exception as e:
log_operation('error', f"Sync failed for {kuerzel}: {e}", context=ctx)
log_operation('info', f"Handler duration (failed): {time.time() - start_time}", context=ctx)
return {'status': 500, 'body': {'error': str(e)}}
finally:
# Always close resources to prevent memory leaks
if service is not None:
@@ -1068,11 +1073,6 @@ async def handler(input_data: Dict[str, Any], ctx: FlowContext) -> None:
redis_client.close()
except Exception as e:
log_operation('debug', f"Error closing Redis client: {e}", context=ctx)
except Exception as e:
log_operation('error', f"Sync failed for {kuerzel}: {e}", context=ctx)
log_operation('info', f"Handler duration (failed): {time.time() - start_time}", context=ctx)
return {'status': 500, 'body': {'error': str(e)}}
finally:
# Ensure lock is always released
clear_employee_lock(redis_client, kuerzel, ctx)