51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""
|
|
Calendar Sync Cron Step
|
|
|
|
Cron trigger for automatic calendar synchronization.
|
|
Emits calendar_sync_all event to start sync cascade.
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
from calendar_sync_utils import log_operation
|
|
|
|
from motia import cron, FlowContext
|
|
|
|
|
|
config = {
|
|
'name': 'Calendar Sync Cron Job',
|
|
'description': 'Runs calendar sync automatically every 15 minutes',
|
|
'flows': ['advoware-calendar-sync'],
|
|
'triggers': [
|
|
cron("0 */15 * * * *") # Every 15 minutes (6-field: sec min hour day month weekday)
|
|
],
|
|
'enqueues': ['calendar_sync_all']
|
|
}
|
|
|
|
|
|
async def handler(input_data: dict, ctx: FlowContext):
|
|
"""Cron handler that triggers the calendar sync cascade."""
|
|
try:
|
|
log_operation('info', "Calendar Sync Cron: Starting to emit sync-all event", context=ctx)
|
|
|
|
# Enqueue sync-all event
|
|
await ctx.enqueue({
|
|
"topic": "calendar_sync_all",
|
|
"data": {
|
|
"triggered_by": "cron"
|
|
}
|
|
})
|
|
|
|
log_operation('info', "Calendar Sync Cron: Emitted sync-all event", context=ctx)
|
|
return {
|
|
'status': 'completed',
|
|
'triggered_by': 'cron'
|
|
}
|
|
|
|
except Exception as e:
|
|
log_operation('error', f"Fehler beim Cron-Job: {e}", context=ctx)
|
|
return {
|
|
'status': 'error',
|
|
'error': str(e)
|
|
}
|