Refactor calendar sync to prioritize oldest synced employees with human-readable timestamps

This commit is contained in:
root
2025-10-26 08:58:48 +00:00
parent b18e770f12
commit 96eabe3db6
4 changed files with 59 additions and 26 deletions

View File

@@ -98,9 +98,19 @@ def set_employee_lock(redis_client, kuerzel, triggered_by, context=None):
return True
def clear_employee_lock(redis_client, kuerzel, context=None):
"""Clear lock for employee sync operation."""
"""Clear lock for employee sync operation and update last-synced timestamp."""
try:
employee_lock_key = f'calendar_sync_lock_{kuerzel}'
employee_last_synced_key = f'calendar_sync_last_synced_{kuerzel}'
# Update last-synced timestamp (no TTL, persistent)
import time
current_time = int(time.time())
redis_client.set(employee_last_synced_key, current_time)
# Delete the lock
redis_client.delete(employee_lock_key)
log_operation('debug', f"Cleared lock and updated last-synced for {kuerzel} to {current_time}", context=context)
except Exception as e:
log_operation('warning', f"Failed to clear lock for {kuerzel}: {e}", context=context)
log_operation('warning', f"Failed to clear lock and update last-synced for {kuerzel}: {e}", context=context)