Add final statistics logging to event step showing operations performed
This commit is contained in:
@@ -597,6 +597,7 @@ async def process_new_from_advoware(state, conn, service, calendar_id, kuerzel,
|
|||||||
kuerzel, int(frnr), event_id
|
kuerzel, int(frnr), event_id
|
||||||
)
|
)
|
||||||
log_operation('info', f"Phase 1: Created new from Advoware: frNr {frnr}, event_id {event_id}", context=context)
|
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
|
await asyncio.sleep(0.1) # Small delay to avoid rate limits
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_operation('warning', f"Phase 1: Failed to process new Advoware {frnr}: {e}", context=context)
|
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
|
kuerzel, int(frnr), event_id
|
||||||
)
|
)
|
||||||
log_operation('info', f"Phase 2: Created new from Google: event_id {event_id}, frNr {frnr}", context=context)
|
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:
|
else:
|
||||||
log_operation('warning', f"Phase 2: Skipped DB insert for Google event {event_id}, frNr is None", context=context)
|
log_operation('warning', f"Phase 2: Skipped DB insert for Google event {event_id}, frNr is None", context=context)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -654,6 +656,7 @@ async def process_deleted_entries(state, conn, service, calendar_id, kuerzel, ad
|
|||||||
async with conn.transaction():
|
async with conn.transaction():
|
||||||
await conn.execute("UPDATE calendar_sync SET deleted = TRUE, sync_status = 'synced' WHERE sync_id = $1;", row['sync_id'])
|
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)
|
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:
|
elif not adv_exists:
|
||||||
# Missing in Advoware
|
# Missing in Advoware
|
||||||
strategy = row['sync_strategy']
|
strategy = row['sync_strategy']
|
||||||
@@ -804,6 +807,7 @@ async def process_updates(state, conn, service, calendar_id, kuerzel, advoware,
|
|||||||
async with conn.transaction():
|
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))
|
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)
|
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
|
await asyncio.sleep(0.1) # Small delay to avoid rate limits
|
||||||
elif google_ts and google_ts > row['last_sync']:
|
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)
|
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_appointments': [],
|
||||||
'adv_map': {},
|
'adv_map': {},
|
||||||
'google_events': [],
|
'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():
|
async def reload_db_indexes():
|
||||||
@@ -952,6 +962,10 @@ async def handler(event_data, context):
|
|||||||
finally:
|
finally:
|
||||||
await conn.close()
|
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)
|
log_operation('info', f"Calendar sync completed for {kuerzel}", context=context)
|
||||||
return {'status': 200, 'body': {'status': 'completed', 'kuerzel': kuerzel}}
|
return {'status': 200, 'body': {'status': 'completed', 'kuerzel': kuerzel}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user