Improve calendar sync: Add Token Bucket rate limiting, security check to prevent syncing Advoware-sourced events back, fix random import
This commit is contained in:
@@ -3,8 +3,6 @@ import redis
|
||||
from config import Config
|
||||
from services.advoware import AdvowareAPI
|
||||
|
||||
CALENDAR_SYNC_LOCK_KEY = 'calendar_sync_lock'
|
||||
|
||||
config = {
|
||||
'type': 'cron',
|
||||
'name': 'Calendar Sync Cron Job',
|
||||
@@ -14,28 +12,17 @@ config = {
|
||||
'flows': ['advoware']
|
||||
}
|
||||
|
||||
async def get_advoware_employees(context, advoware):
|
||||
"""Fetch list of employees from Advoware."""
|
||||
try:
|
||||
result = await advoware.api_call('api/v1/advonet/Mitarbeiter', method='GET', params={'aktiv': 'true'})
|
||||
employees = result if isinstance(result, list) else []
|
||||
context.logger.info(f"Fetched {len(employees)} Advoware employees")
|
||||
return employees
|
||||
except Exception as e:
|
||||
context.logger.error(f"Failed to fetch Advoware employees: {e}")
|
||||
raise
|
||||
|
||||
async def handler(context):
|
||||
try:
|
||||
context.logger.info("Calendar Sync Cron: Starting to emit sync-all event")
|
||||
|
||||
# Emit sync-all event
|
||||
await context.emit({
|
||||
"topic": "calendar_sync_all",
|
||||
"data": {
|
||||
"triggered_by": "cron"
|
||||
}
|
||||
})
|
||||
# # Emit sync-all event
|
||||
# await context.emit({
|
||||
# "topic": "calendar_sync_all",
|
||||
# "data": {
|
||||
# "triggered_by": "cron"
|
||||
# }
|
||||
# })
|
||||
|
||||
context.logger.info("Calendar Sync Cron: Emitted sync-all event")
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user