fix: replace log_operation() with ctx.logger in calendar_sync_all_step – comply with INDEX.md logging standard
This commit is contained in:
@@ -40,7 +40,7 @@ async def handler(input_data: Dict[str, Any], ctx: FlowContext) -> None:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
triggered_by = input_data.get('triggered_by', 'unknown')
|
triggered_by = input_data.get('triggered_by', 'unknown')
|
||||||
log_operation('info', f"Calendar Sync All: Starting to emit events for oldest employees, triggered by {triggered_by}", context=ctx)
|
ctx.logger.info(f"Calendar Sync All: Starting to emit events for oldest employees, triggered by {triggered_by}")
|
||||||
|
|
||||||
# Initialize Advoware service
|
# Initialize Advoware service
|
||||||
advoware = AdvowareService(ctx)
|
advoware = AdvowareService(ctx)
|
||||||
@@ -48,7 +48,7 @@ async def handler(input_data: Dict[str, Any], ctx: FlowContext) -> None:
|
|||||||
# Fetch employees
|
# Fetch employees
|
||||||
employees = await get_advoware_employees(advoware, ctx)
|
employees = await get_advoware_employees(advoware, ctx)
|
||||||
if not employees:
|
if not employees:
|
||||||
log_operation('error', "Keine Mitarbeiter gefunden. All-Sync abgebrochen.", context=ctx)
|
ctx.logger.error("Keine Mitarbeiter gefunden. All-Sync abgebrochen.")
|
||||||
raise RuntimeError("Keine Mitarbeiter gefunden. All-Sync abgebrochen.")
|
raise RuntimeError("Keine Mitarbeiter gefunden. All-Sync abgebrochen.")
|
||||||
|
|
||||||
redis_client = get_redis_client(ctx)
|
redis_client = get_redis_client(ctx)
|
||||||
@@ -74,17 +74,17 @@ async def handler(input_data: Dict[str, Any], ctx: FlowContext) -> None:
|
|||||||
return datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
|
return datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
sorted_list_str = ", ".join(f"{k} ({format_timestamp(employee_timestamps[k])})" for k in sorted_kuerzel)
|
sorted_list_str = ", ".join(f"{k} ({format_timestamp(employee_timestamps[k])})" for k in sorted_kuerzel)
|
||||||
log_operation('info', f"Calendar Sync All: Sorted employees by last synced: {sorted_list_str}", context=ctx)
|
ctx.logger.info(f"Calendar Sync All: Sorted employees by last synced: {sorted_list_str}")
|
||||||
|
|
||||||
# Calculate number to sync: ceil(N / 10)
|
# Calculate number to sync: ceil(N / 10)
|
||||||
num_to_sync = math.ceil(len(sorted_kuerzel) / 1)
|
num_to_sync = math.ceil(len(sorted_kuerzel) / 1)
|
||||||
log_operation('info', f"Calendar Sync All: Total employees {len(sorted_kuerzel)}, syncing {num_to_sync} oldest", context=ctx)
|
ctx.logger.info(f"Calendar Sync All: Total employees {len(sorted_kuerzel)}, syncing {num_to_sync} oldest")
|
||||||
|
|
||||||
# Emit for the oldest num_to_sync employees, if not locked
|
# Emit for the oldest num_to_sync employees, if not locked
|
||||||
emitted_count = 0
|
emitted_count = 0
|
||||||
for kuerzel in sorted_kuerzel[:num_to_sync]:
|
for kuerzel in sorted_kuerzel[:num_to_sync]:
|
||||||
if not set_employee_lock(redis_client, kuerzel, triggered_by, ctx):
|
if not set_employee_lock(redis_client, kuerzel, triggered_by, ctx):
|
||||||
log_operation('info', f"Calendar Sync All: Sync already active for {kuerzel}, skipping", context=ctx)
|
ctx.logger.info(f"Calendar Sync All: Sync already active for {kuerzel}, skipping")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Emit event for this employee
|
# Emit event for this employee
|
||||||
@@ -95,11 +95,11 @@ async def handler(input_data: Dict[str, Any], ctx: FlowContext) -> None:
|
|||||||
"triggered_by": triggered_by
|
"triggered_by": triggered_by
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
log_operation('info', f"Calendar Sync All: Emitted event for employee {kuerzel} (last synced: {format_timestamp(employee_timestamps[kuerzel])})", context=ctx)
|
ctx.logger.info(f"Calendar Sync All: Emitted event for employee {kuerzel} (last synced: {format_timestamp(employee_timestamps[kuerzel])})")
|
||||||
emitted_count += 1
|
emitted_count += 1
|
||||||
|
|
||||||
log_operation('info', f"Calendar Sync All: Completed, emitted {emitted_count} events", context=ctx)
|
ctx.logger.info(f"Calendar Sync All: Completed, emitted {emitted_count} events")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_operation('error', f"Fehler beim All-Sync: {e}", context=ctx)
|
ctx.logger.error(f"Fehler beim All-Sync: {e}")
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user