Pre-optimization commit: Calendar sync implementation with hub design

This commit is contained in:
root
2025-10-23 08:29:46 +00:00
parent 2f9203cac2
commit 1de5bcd369
12 changed files with 506 additions and 954 deletions

View File

@@ -1,4 +1,8 @@
import json
import redis
from config import Config
CALENDAR_SYNC_LOCK_KEY = 'calendar_sync_lock'
config = {
'type': 'cron',
@@ -10,7 +14,25 @@ config = {
async def handler(event, context):
try:
context.logger.info("Calendar Sync Cron: Starte automatische Synchronisation alle 15 Minuten")
# Prüfe ob bereits ein Sync 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
)
if redis_client.get(CALENDAR_SYNC_LOCK_KEY):
context.logger.info("Calendar Sync Cron: Sync bereits aktiv, überspringe")
return {
'status': 'skipped',
'reason': 'sync_already_running',
'triggered_by': 'cron'
}
# Setze Lock für 30 Minuten (Sync sollte max 30 Minuten dauern)
redis_client.set(CALENDAR_SYNC_LOCK_KEY, 'cron', ex=1800)
context.logger.info("Calendar Sync Cron: Lock gesetzt, starte automatische Synchronisation alle 15 Minuten")
# Emit Event für den Sync
await context.emit({