refactor(logging): standardize status code handling and enhance logging in webhook and cron handlers

This commit is contained in:
bsiggel
2026-03-08 22:09:22 +00:00
parent a0cf845877
commit 1c765d1eec
15 changed files with 61 additions and 64 deletions

View File

@@ -38,7 +38,7 @@ async def handler(request: ApiRequest, ctx: FlowContext) -> ApiResponse:
kuerzel = body.get('kuerzel')
if not kuerzel:
return ApiResponse(
status_code=400,
status=400,
body={
'error': 'kuerzel required',
'message': 'Please provide kuerzel in body'
@@ -57,7 +57,7 @@ async def handler(request: ApiRequest, ctx: FlowContext) -> ApiResponse:
}
})
return ApiResponse(
status_code=200,
status=200,
body={
'status': 'triggered',
'message': 'Calendar sync triggered for all employees',
@@ -71,7 +71,7 @@ async def handler(request: ApiRequest, ctx: FlowContext) -> ApiResponse:
if not set_employee_lock(redis_client, kuerzel_upper, 'api', ctx):
ctx.logger.info(f"Calendar Sync API: Sync already active for {kuerzel_upper}, skipping")
return ApiResponse(
status_code=409,
status=409,
body={
'status': 'conflict',
'message': f'Calendar sync already active for {kuerzel_upper}',
@@ -92,7 +92,7 @@ async def handler(request: ApiRequest, ctx: FlowContext) -> ApiResponse:
})
return ApiResponse(
status_code=200,
status=200,
body={
'status': 'triggered',
'message': f'Calendar sync triggered for {kuerzel_upper}',
@@ -104,7 +104,7 @@ async def handler(request: ApiRequest, ctx: FlowContext) -> ApiResponse:
except Exception as e:
ctx.logger.error(f"Error in API trigger: {e}")
return ApiResponse(
status_code=500,
status=500,
body={
'error': 'Internal server error',
'details': str(e)

View File

@@ -24,10 +24,13 @@ config = {
}
async def handler(input_data: Dict[str, Any], ctx: FlowContext) -> None:
async def handler(input_data: None, ctx: FlowContext) -> None:
"""Cron handler that triggers the calendar sync cascade."""
try:
log_operation('info', "Calendar Sync Cron: Starting to emit sync-all event", context=ctx)
ctx.logger.info("=" * 80)
ctx.logger.info("🕐 CALENDAR SYNC CRON: STARTING")
ctx.logger.info("=" * 80)
ctx.logger.info("Emitting sync-all event")
# Enqueue sync-all event
await ctx.enqueue({
@@ -37,7 +40,11 @@ async def handler(input_data: Dict[str, Any], ctx: FlowContext) -> None:
}
})
log_operation('info', "Calendar Sync Cron: Emitted sync-all event", context=ctx)
ctx.logger.info("Calendar sync-all event emitted successfully")
ctx.logger.info("=" * 80)
except Exception as e:
log_operation('error', f"Fehler beim Cron-Job: {e}", context=ctx)
ctx.logger.error("=" * 80)
ctx.logger.error("❌ ERROR: CALENDAR SYNC CRON")
ctx.logger.error(f"Error: {e}")
ctx.logger.error("=" * 80)