Overview
Framefox provides a robust background task system for executing long-running operations asynchronously. Tasks are queued, distributed to workers, and executed outside the request/response cycle.Task System Features
- Multiple Brokers: Database and RabbitMQ transport support
- Priority Queues: Execute important tasks first
- Scheduled Tasks: Delay or schedule tasks for specific times
- Retry Logic: Automatic retry on failure
- Worker Management: Concurrent task processing
- Event Integration: Task lifecycle events
Quick Start
Defining Tasks
Use the@AsyncTask decorator to define background tasks:
Queuing Tasks
Queue tasks for background execution:TaskManager
TheTaskManager provides full control over task queuing:
Task Decorator Options
Queues and Priorities
Multiple Queues
Organize tasks into different queues:Priority Handling
Tasks with higher priority execute first within the same queue:Worker Manager
TheWorkerManager processes tasks from queues:
Running Workers
CLI Command
Run workers using the Framefox CLI:Programmatic Worker
Create a worker script:Task Status and Retry
Task Status
Tasks have the following statuses:Automatic Retry
Tasks automatically retry on failure:Manual Retry Logic
Scheduled and Delayed Tasks
Delay Execution
Schedule for Specific Time
Recurring Tasks
Implement recurring tasks manually:Event Integration
Listen to task lifecycle events:Broker Configuration
Database Broker
Default broker using your database:RabbitMQ Broker
For high-throughput scenarios:Best Practices
- Idempotency: Make tasks idempotent (safe to retry)
- Task Size: Keep tasks focused and relatively small
- Error Handling: Handle expected errors gracefully
- Logging: Log task execution for debugging
- Monitoring: Track task success/failure rates
- Queue Organization: Use multiple queues for different priorities
- Resource Management: Clean up resources in tasks
- Testing: Test tasks independently from the queue system