Implement atomic locking in API and cron steps for per-employee parallel sync

This commit is contained in:
root
2025-10-24 00:48:25 +00:00
parent 9a1eb5bf0b
commit 2eb8330b1d
3 changed files with 18 additions and 8 deletions

View File

@@ -50,6 +50,19 @@ async def handler(context):
context.logger.info(f"DEBUG: Überspringe {kuerzel}, nur SB wird gesynct")
continue
employee_lock_key = f'calendar_sync_lock_{kuerzel}'
redis_client = redis.Redis(
host=Config.REDIS_HOST,
port=int(Config.REDIS_PORT),
db=int(Config.REDIS_DB_CALENDAR_SYNC),
socket_timeout=Config.REDIS_TIMEOUT_SECONDS
)
if redis_client.set(employee_lock_key, 'cron', ex=1800, nx=True) is None:
context.logger.info(f"Calendar Sync Cron: Sync bereits aktiv für {kuerzel}, überspringe")
continue
# Emit event for this employee
await context.emit({
"topic": "calendar_sync_employee",