Scheduling — Aquilia Documentation
Comprehensive guide and documentation for Scheduling in the Aquilia framework. View API reference, examples, and implementation patterns.
Background Tasks / Scheduling Periodic Task Scheduling Schedule tasks to run at fixed intervals or precise calendar times. The scheduler loop automatically detects due tasks and enqueues them into the priority queue. How Scheduling Works Aquilia handles scheduling without external services. When TaskManager.start() runs, a dedicated scheduler loop evaluates periodic registrations on every clock tick (determined by scheduler_tick). Task Registration: Tasks decorated with schedule= are registered with the task manager. Tick Loop: The scheduler coroutine wakes up every tick interval (default: 15s) to check due tasks. Due Calculation: The next execution timestamp is calculated based on the interval or cron specification. Job Enqueue: When due, a new Job instance is pushed onto the priority queue. Execution: Available workers pop and execute the task concurrently. SCHEDULER LOOP every() / cron() Wakes up on tick interval TASK QUEUE Priority Heap Due jobs ordered by time WORKER POOL Async Coroutines Execute due jobs enqueue() poll() every() — Interval-based Schedules Specifies that a task runs at fixed intervals. The scheduler calculates intervals dynamically using floats. from aquilia.tasks import task, every @task(schedule=every(seconds=30)) async def report_heartbeat(): # Runs every 30 seconds ... @task(schedule=every(minutes=5)) async def prune_temp_files(): # Runs every 5 minutes ... @task(schedule=every(hours=12)) async def check_database_integrity(): # Runs every 12 hours ... @task(schedule=every(days=1, hours=6)) async def compile_statistics(): # Runs every 30 hours ... Interval Schedule Layout Declaration Total Cooldown Runs Per Day ))} cron() — Calendar-based Schedules Specifies that a task runs on a cron schedule. Supports standard 5-field cron strings. from aquilia.tasks import task, cron # Format: "minute hour day_of_month month day_of_week" @task(schedule=cron("0 9 * * *")) async def daily_9am_reports(): # Runs at exactly 9:00 AM every day ... @task(schedule=cron("*/15 * * * *")) async def sync_external_inventory(): # Runs at :00, :15, :30, and :45 of every hour ... @task(schedule=cron("0 0 1 * *")) async def monthly_invoice_run(): # Runs at midnight on the first day of every month ... Expression Format Specification Position Field Name Valid Values Supported Symbols ))} Scheduling Best Practices , , , , ].map((item, i) => ( ))} )
Go to Homepage