Skip to content

Files

81 lines (65 loc) · 2.34 KB

installation.md

File metadata and controls

81 lines (65 loc) · 2.34 KB

Installation Guide

fib-flow is a workflow management system built on fibjs, designed for orchestrating complex task dependencies and managing distributed task execution.

Table of Contents

Installation

Prerequisites

  • 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

Quick Start

Basic Setup

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 or sqlite::memory:
    • MySQL: mysql://user:pass@host:3306/database
    • PostgreSQL: psql://user:pass@host:5432/database
  • poll_interval: How often to check for new tasks (in milliseconds)
  • max_retries: Number of retry attempts for failed tasks
  • retry_interval: Time to wait before retrying (in seconds)
  • max_concurrent_tasks: Maximum number of tasks running simultaneously

Task Registration

// 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 data
  • task.id: Unique identifier for the task
  • task.status: Current status of the task
  • task.attempts: Number of execution attempts

Running Tasks

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.