Add recreated count to sync statistics

This commit is contained in:
root
2025-10-24 06:32:33 +00:00
parent 858d3d4fb3
commit 72ee01b74b

View File

@@ -681,6 +681,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 advoware_frnr = $1, sync_status = 'synced', last_sync = $3 WHERE sync_id = $2;", int(new_frnr), row['sync_id'], datetime.datetime.now(BERLIN_TZ)) await conn.execute("UPDATE calendar_sync SET advoware_frnr = $1, sync_status = 'synced', last_sync = $3 WHERE sync_id = $2;", int(new_frnr), row['sync_id'], datetime.datetime.now(BERLIN_TZ))
log_operation('info', f"Phase 3: Recreated Advoware appointment {new_frnr} for sync_id {row['sync_id']}", context=context) log_operation('info', f"Phase 3: Recreated Advoware appointment {new_frnr} for sync_id {row['sync_id']}", context=context)
state['stats']['recreated'] += 1
else: else:
log_operation('warning', f"Phase 3: Failed to recreate Advoware for sync_id {row['sync_id']}, frNr is None", context=context) log_operation('warning', f"Phase 3: Failed to recreate Advoware for sync_id {row['sync_id']}, frNr is None", context=context)
async with conn.transaction(): async with conn.transaction():
@@ -740,6 +741,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 google_event_id = $1, sync_status = 'synced', last_sync = $3 WHERE sync_id = $2;", new_event_id, row['sync_id'], datetime.datetime.now(BERLIN_TZ)) await conn.execute("UPDATE calendar_sync SET google_event_id = $1, sync_status = 'synced', last_sync = $3 WHERE sync_id = $2;", new_event_id, row['sync_id'], datetime.datetime.now(BERLIN_TZ))
log_operation('info', f"Phase 3: Recreated Google event {new_event_id} for sync_id {row['sync_id']}", context=context) log_operation('info', f"Phase 3: Recreated Google event {new_event_id} for sync_id {row['sync_id']}", context=context)
state['stats']['recreated'] += 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 3: Failed to recreate Google for sync_id {row['sync_id']}: {e}", context=context) log_operation('warning', f"Phase 3: Failed to recreate Google for sync_id {row['sync_id']}: {e}", context=context)
@@ -895,7 +897,8 @@ async def handler(event_data, context):
'new_adv_to_google': 0, 'new_adv_to_google': 0,
'new_google_to_adv': 0, 'new_google_to_adv': 0,
'deleted': 0, 'deleted': 0,
'updated': 0 'updated': 0,
'recreated': 0
} }
} }
@@ -956,15 +959,12 @@ async def handler(event_data, context):
# Phase 4: Update existing entries if changed # Phase 4: Update existing entries if changed
await process_updates(state, conn, service, calendar_id, kuerzel, advoware, context) await process_updates(state, conn, service, calendar_id, kuerzel, advoware, context)
# Update last_sync timestamps
log_operation('debug', "Updated last_sync timestamps", context=context)
finally: finally:
await conn.close() await conn.close()
# Log final statistics # Log final statistics
stats = state['stats'] 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"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']}, Recreated: {stats['recreated']}", 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}}