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 typing import Dict, Any
|
|
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 1 * * *") # Every 15 minutes at second 0 (6-field: sec min hour day month weekday)
|
|
],
|
|
'enqueues': ['calendar_sync_all']
|
|
}
|
|
|
|
|
|
async def handler(input_data: None, ctx: FlowContext) -> None:
|
|
"""Cron handler that triggers the calendar sync cascade."""
|
|
try:
|
|
ctx.logger.info("=" * 80)
|
|
ctx.logger.info("🕐 CALENDAR SYNC CRON: STARTING")
|
|
ctx.logger.info("=" * 80)
|
|
ctx.logger.info("Emitting sync-all event")
|
|
|
|
# Enqueue sync-all event
|
|
await ctx.enqueue({
|
|
"topic": "calendar_sync_all",
|
|
"data": {
|
|
"triggered_by": "cron"
|
|
}
|
|
})
|
|
|
|
ctx.logger.info("✅ Calendar sync-all event emitted successfully")
|
|
ctx.logger.info("=" * 80)
|
|
|
|
except Exception as e:
|
|
ctx.logger.error("=" * 80)
|
|
ctx.logger.error("❌ ERROR: CALENDAR SYNC CRON")
|
|
ctx.logger.error(f"Error: {e}")
|
|
ctx.logger.error("=" * 80)
|