Add final statistics logging to event step showing operations performed

This commit is contained in:
root
2025-10-24 06:16:02 +00:00
parent c14273cac9
commit 858d3d4fb3

View File

@@ -597,6 +597,7 @@ async def process_new_from_advoware(state, conn, service, calendar_id, kuerzel,
kuerzel, int(frnr), event_id
)
log_operation('info', f"Phase 1: Created new from Advoware: frNr {frnr}, event_id {event_id}", context=context)
state['stats']['new_adv_to_google'] += 1
await asyncio.sleep(0.1) # Small delay to avoid rate limits
except Exception as e:
log_operation('warning', f"Phase 1: Failed to process new Advoware {frnr}: {e}", context=context)
@@ -623,6 +624,7 @@ async def process_new_from_google(state, conn, service, calendar_id, kuerzel, ad
kuerzel, int(frnr), event_id
)
log_operation('info', f"Phase 2: Created new from Google: event_id {event_id}, frNr {frnr}", context=context)
state['stats']['new_google_to_adv'] += 1
else:
log_operation('warning', f"Phase 2: Skipped DB insert for Google event {event_id}, frNr is None", context=context)
except Exception as e:
@@ -654,6 +656,7 @@ async def process_deleted_entries(state, conn, service, calendar_id, kuerzel, ad
async with conn.transaction():
await conn.execute("UPDATE calendar_sync SET deleted = TRUE, sync_status = 'synced' WHERE sync_id = $1;", row['sync_id'])
log_operation('info', f"Phase 3: Soft deleted sync_id {row['sync_id']} (both missing)", context=context)
state['stats']['deleted'] += 1
elif not adv_exists:
# Missing in Advoware
strategy = row['sync_strategy']
@@ -804,6 +807,7 @@ async def process_updates(state, conn, service, calendar_id, kuerzel, advoware,
async with conn.transaction():
await conn.execute("UPDATE calendar_sync SET sync_status = 'synced', last_sync = $2 WHERE sync_id = $1;", row['sync_id'], datetime.datetime.now(BERLIN_TZ))
log_operation('info', f"Phase 4: Updated Google event {event_id} from Advoware frNr {frnr}", context=context)
state['stats']['updated'] += 1
await asyncio.sleep(0.1) # Small delay to avoid rate limits
elif google_ts and google_ts > row['last_sync']:
log_operation('warning', f"Phase 4: Unauthorized change in Google event {event_id}, resetting to Advoware frNr {frnr}", context=context)
@@ -886,7 +890,13 @@ async def handler(event_data, context):
'adv_appointments': [],
'adv_map': {},
'google_events': [],
'google_map': {}
'google_map': {},
'stats': {
'new_adv_to_google': 0,
'new_google_to_adv': 0,
'deleted': 0,
'updated': 0
}
}
async def reload_db_indexes():
@@ -952,6 +962,10 @@ async def handler(event_data, context):
finally:
await conn.close()
# Log final statistics
stats = state['stats']
log_operation('info', f"Sync statistics for {kuerzel}: New Adv->Google: {stats['new_adv_to_google']}, New Google->Adv: {stats['new_google_to_adv']}, Deleted: {stats['deleted']}, Updated: {stats['updated']}", context=context)
log_operation('info', f"Calendar sync completed for {kuerzel}", context=context)
return {'status': 200, 'body': {'status': 'completed', 'kuerzel': kuerzel}}