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

@@ -12,8 +12,7 @@ config = {
'flows': ['advoware']
}
async def handler(req):
context = req.context
async def handler(req, context):
try:
# Konfiguration aus Request-Body
body = req.get('body', {})
@@ -37,7 +36,7 @@ async def handler(req):
socket_timeout=Config.REDIS_TIMEOUT_SECONDS
)
if redis_client.get(employee_lock_key):
if redis_client.set(employee_lock_key, 'api', ex=1800, nx=True) is None:
context.logger.info(f"Calendar Sync API: Sync bereits aktiv für {kuerzel}, überspringe")
return {
'status': 409,
@@ -51,9 +50,7 @@ async def handler(req):
context.logger.info(f"Calendar Sync API aufgerufen für {kuerzel}")
# Setze Lock für 30 Minuten
redis_client.set(employee_lock_key, 'api', ex=1800)
context.logger.info(f"Calendar Sync API: Lock gesetzt für {kuerzel}")
# Lock erfolgreich gesetzt, jetzt emittieren
# Emit Event für den Sync
await context.emit({