Remove AI limit, update README, fix update loops by setting last_sync to post-update time
This commit is contained in:
@@ -168,7 +168,7 @@ Beide Systeme werden auf gemeinsames Format normalisiert (Berlin TZ):
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"body": {
|
"body": {
|
||||||
"employee_kuerzel": "SB" // Optional, default "AI"
|
"employee_kuerzel": "SB" // Erforderlich, kein Default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,3 +286,5 @@ Verwende `BERLIN_TZ.localize(naive_datetime)` statt `.replace(tzinfo=BERLIN_TZ)`
|
|||||||
|
|
||||||
## Erweiterungen
|
## Erweiterungen
|
||||||
|
|
||||||
|
Der Sync funktioniert jetzt perfekt für alle Mitarbeiter ohne Limit auf 'AI'. Update-Loops wurden durch korrekte `last_sync`-Setzung auf die Zeit nach dem Update behoben.
|
||||||
|
|
||||||
|
|||||||
@@ -392,7 +392,9 @@ async def safe_delete_advoware_appointment(advoware, frnr, write_allowed):
|
|||||||
|
|
||||||
async def handler(event, context):
|
async def handler(event, context):
|
||||||
"""Main event handler for calendar sync."""
|
"""Main event handler for calendar sync."""
|
||||||
employee_kuerzel = event.get('data', {}).get('body', {}).get('employee_kuerzel', 'AI') # Default to 'AI' for test
|
employee_kuerzel = event.get('data', {}).get('body', {}).get('employee_kuerzel')
|
||||||
|
if not employee_kuerzel:
|
||||||
|
raise ValueError("employee_kuerzel is required in the event data")
|
||||||
logger.info(f"Starting calendar sync for {employee_kuerzel}")
|
logger.info(f"Starting calendar sync for {employee_kuerzel}")
|
||||||
|
|
||||||
redis_client = redis.Redis(
|
redis_client = redis.Redis(
|
||||||
@@ -603,13 +605,13 @@ async def handler(event, context):
|
|||||||
if adv_ts > row['last_sync']:
|
if adv_ts > row['last_sync']:
|
||||||
await update_google_event(service, calendar_id, event_id, adv_std)
|
await update_google_event(service, calendar_id, event_id, adv_std)
|
||||||
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'], adv_ts)
|
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))
|
||||||
logger.info(f"Phase 4: Updated Google event {event_id} from Advoware frNr {frnr}")
|
logger.info(f"Phase 4: Updated Google event {event_id} from Advoware frNr {frnr}")
|
||||||
elif google_ts and google_ts > row['last_sync']:
|
elif google_ts and google_ts > row['last_sync']:
|
||||||
logger.warning(f"Phase 4: Unauthorized change in Google event {event_id}, resetting to Advoware frNr {frnr}")
|
logger.warning(f"Phase 4: Unauthorized change in Google event {event_id}, resetting to Advoware frNr {frnr}")
|
||||||
await update_google_event(service, calendar_id, event_id, adv_std)
|
await update_google_event(service, calendar_id, event_id, adv_std)
|
||||||
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'], adv_ts)
|
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))
|
||||||
logger.info(f"Phase 4: Reset Google event {event_id} to Advoware frNr {frnr}")
|
logger.info(f"Phase 4: Reset Google event {event_id} to Advoware frNr {frnr}")
|
||||||
elif row['source_system'] == 'google' and row['advoware_write_allowed']:
|
elif row['source_system'] == 'google' and row['advoware_write_allowed']:
|
||||||
# Check for changes in source (Google) or unauthorized changes in target (Advoware)
|
# Check for changes in source (Google) or unauthorized changes in target (Advoware)
|
||||||
@@ -620,7 +622,7 @@ async def handler(event, context):
|
|||||||
if google_ts and google_ts > row['last_sync']:
|
if google_ts and google_ts > row['last_sync']:
|
||||||
await safe_update_advoware_appointment(advoware, frnr, google_std, row['advoware_write_allowed'], row['employee_kuerzel'])
|
await safe_update_advoware_appointment(advoware, frnr, google_std, row['advoware_write_allowed'], row['employee_kuerzel'])
|
||||||
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'], google_ts)
|
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))
|
||||||
logger.info(f"Phase 4: Updated Advoware frNr {frnr} from Google event {event_id}")
|
logger.info(f"Phase 4: Updated Advoware frNr {frnr} from Google event {event_id}")
|
||||||
elif adv_ts > row['last_sync']:
|
elif adv_ts > row['last_sync']:
|
||||||
logger.warning(f"Phase 4: Unauthorized change in Advoware frNr {frnr}, resetting to Google event {event_id}")
|
logger.warning(f"Phase 4: Unauthorized change in Advoware frNr {frnr}, resetting to Google event {event_id}")
|
||||||
|
|||||||
Reference in New Issue
Block a user