fib-flow is a workflow management system built on fibjs, designed for orchestrating complex task dependencies and managing distributed task execution.
- fibjs >= 0.33.0
- One of the following databases:
- SQLite3 (included)
- MySQL 5.7+
- PostgreSQL 12+
Install fib-flow via fibjs:
fibjs --install fib-flow
const { TaskManager } = require('fib-flow');
// Initialize task manager with options
const taskManager = new TaskManager({
dbConnection: 'sqlite:tasks.db', // Database connection string
poll_interval: 1000, // Poll interval in milliseconds
max_retries: 3, // Maximum retry attempts
retry_interval: 300, // Retry interval in seconds
max_concurrent_tasks: 10 // Maximum concurrent tasks
});
// Initialize database
taskManager.db.setup();
Configuration Options:
dbConnection
: Database connection string (supports SQLite, MySQL, PostgreSQL)- SQLite:
sqlite:tasks.db
orsqlite::memory:
- MySQL:
mysql://user:pass@host:3306/database
- PostgreSQL:
psql://user:pass@host:5432/database
- SQLite:
poll_interval
: How often to check for new tasks (in milliseconds)max_retries
: Number of retry attempts for failed tasksretry_interval
: Time to wait before retrying (in seconds)max_concurrent_tasks
: Maximum number of tasks running simultaneously
// Register task handlers
taskManager.use('sendEmail', async (task) => {
const { to, subject, body } = task.payload;
await sendEmail(to, subject, body);
return { sent: true };
});
Task Handler Parameters:
task.payload
: Contains the task input datatask.id
: Unique identifier for the tasktask.status
: Current status of the tasktask.attempts
: Number of execution attempts
For comprehensive examples, see Usage Examples.
Basic startup example:
taskManager.start();
taskManager.async('simple_task', { data: 'test' });
For error handling and advanced configurations, refer to the Advanced Guide.