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: 0, // No delay between retries
timeout: 60, // Default task timeout 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)timeout
: Default task execution timeout (in seconds)max_concurrent_tasks
: Maximum number of tasks running simultaneously
// Basic handler registration
taskManager.use('sendEmail', async (task) => {
const { to, subject, body } = task.payload;
await sendEmail(to, subject, body);
return { sent: true };
});
// Handler registration with options
taskManager.use('processImage', {
handler: async (task) => {
const { path } = task.payload;
await processImage(path);
return { processed: true };
},
timeout: 120, // 2 minutes timeout
max_retries: 2, // Maximum 2 retries
retry_interval: 30, // Retry every 30 seconds
priority: 5 // Higher priority task
});
Task Handler Options:
handler
: The function that processes the tasktimeout
: Task-specific timeout in secondsmax_retries
: Maximum retry attempts for this task typeretry_interval
: Retry interval in secondspriority
: Default priority for this task type
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.