refactor: extract common functions to utils

- Add get_redis_client() to calendar_sync_utils.py
- Add get_advoware_employees() to calendar_sync_utils.py
- Add set_employee_lock() and clear_employee_lock() to calendar_sync_utils.py
- Update all step files to use shared utility functions
- Remove duplicate code across calendar_sync_*.py files
This commit is contained in:
root
2025-10-25 09:21:45 +00:00
parent e4bf21e676
commit b18e770f12
4 changed files with 53 additions and 49 deletions

View File

@@ -1,6 +1,7 @@
import json
import redis
from config import Config
from .calendar_sync_utils import get_redis_client, set_employee_lock
config = {
'type': 'api',
@@ -50,14 +51,9 @@ async def handler(req, context):
employee_lock_key = f'calendar_sync_lock_{kuerzel_upper}'
# Prüfe ob bereits ein Sync für diesen Mitarbeiter läuft
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
)
redis_client = get_redis_client(context)
if redis_client.set(employee_lock_key, 'api', ex=1800, nx=True) is None:
if not set_employee_lock(redis_client, kuerzel_upper, 'api', context):
context.logger.info(f"Calendar Sync API: Sync bereits aktiv für {kuerzel_upper}, überspringe")
return {
'status': 409,