Tasks — Aquilia Documentation
Comprehensive guide and documentation for Tasks in the Aquilia framework. View API reference, examples, and implementation patterns.
import from 'lucide-react' Background Tasks / Overview Background Tasks Module Aquilia provides an industry-grade, async-native background task system with priority queues, automatic retries, and scheduled executions. It is a lightweight, integrated replacement for Celery or RQ, running directly inside the asyncio event loop. Quick Start 1. Enable in Workspace Register the task integration inside your workspace.py config using TasksIntegration . # workspace.py from aquilia import Workspace, Module from aquilia.integrations import TasksIntegration workspace = ( Workspace("myapp", version="1.0.0") .runtime(mode="dev", port=8000) .module(Module("core")) .integrate(TasksIntegration( num_workers=4, scheduler_tick=15.0, # Periodic check interval )) ) 2. Define a Task Decorate an async function with @task and configure its queue, priority, and retry policy. # modules/core/tasks.py from aquilia.tasks import task, Priority @task( queue="notifications", priority=Priority.HIGH, max_retries=3, timeout=60.0, ) async def send_notification(user_id: int, message: str) -> bool: """Send a notification to a user.""" # notification logic goes here return True 3. Dispatch from a Controller Call the task asynchronously inside a Controller handler using .delay(). # modules/core/controllers.py from aquilia import Controller, POST, RequestCtx, Response from .tasks import send_notification class NotificationsController(Controller): prefix = "/notifications" @POST("/send") async def send(self, ctx: RequestCtx) -> Response: data = await ctx.json() # Enqueue task for background execution (returns job ID string) job_id = await send_notification.delay( user_id=data["user_id"], message=data["message"] ) return Response.json( ) Key Pillars ))} Subsystem Architecture SCHEDULER every() & cron() Generates periodic triggers TASK MANAGER Registry Lookup Orchestrates lifecycles QUEUE BACKEND Priority Heap Memory Heap queue storage WORKER POOL Async Coroutines Concurrent execution loops Tick check delay() poll() JOB LIFECYCLE STATES , , , , , , ].map((s, i) => ( ))} Job Lifecycle States , , , , , , ].map((item, i) => ( ))} Priority System Aquilia background jobs are ordered in the queue using their integer priority. Lower values take absolute precedence. Level Enum Member Value Typical Use Case , , , ].map((row, i) => ( ))} Subsystem Comparison Feature Aquilia Tasks Celery RQ (Redis Queue) ))} )
Go to Homepage