hflow 0.1.0

A lightweight concurrent task progress manager for CLI applications.
Documentation
  • Coverage
  • 44.44%
    8 out of 18 items documented0 out of 14 items with examples
  • Size
  • Source code size: 12.06 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.9 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • CVALENDB

hflow

hflow is a lightweight, thread-safe task orchestration library for Rust CLI applications. It provides a hierarchical structure to manage and visualize sequential task groups with real-time feedback.

Features

  • Thread-Safe Execution: Utilizes atomic-like synchronization using Arc<Mutex<T>> for state management across threads.
  • Hierarchical Task Management: Organizes work into ExecutionUnit, TaskGroup, and ProgressManager for granular control.
  • Real-time Visual Feedback: Built-in terminal spinner and status indicators with ANSI escape sequences for line clearing.
  • Automatic Error Handling: Integrated process termination on unit failure to ensure system integrity during critical deployments.

Architecture

The library follows a three-tier hierarchy:

  1. ProgressManager: The top-level orchestrator that manages multiple groups.
  2. TaskGroup: A collection of units that are executed sequentially within the group's context.
  3. ExecutionUnit: The atomic unit of work that executes a provided closure in a dedicated background thread.

Installation

Add the following to your Cargo.toml:

[dependencies]
hflow = { git = "https://github.com/cvalendb/hflow" }
colored = "2.1"

Usage Example

The following example demonstrates how to set up a multi-stage deployment process:

use hflow::{ProgressManager, TaskGroup, ExecutionUnit, ExecutionStatus};
use std::thread;
use std::time::Duration;

fn main() {
    let mut manager = ProgressManager::new();

    // Group 1: System Initialization
    let mut init_group = TaskGroup::new();
    
    let check_perms = ExecutionUnit::new(
        "Verifying administrator permissions".to_string(),
        |status| {
            thread::sleep(Duration::from_secs(2));
            let mut guard = status.lock().unwrap();
            *guard = ExecutionStatus::Completed;
        }
    );

    init_group.add_unit(check_perms);
    manager.add_group(init_group);

    // Group 2: Network Configuration
    let mut net_group = TaskGroup::new();
    
    let setup_firewall = ExecutionUnit::new(
        "Configuring firewall rules".to_string(),
        |status| {
            thread::sleep(Duration::from_secs(3));
            let mut guard = status.lock().unwrap();
            *guard = ExecutionStatus::Completed;
        }
    );

    net_group.add_unit(setup_firewall);
    manager.add_group(net_group);

    // Start orchestration
    manager.start();
}

Technical Specifications

  • Concurrency Model: Each ExecutionUnit spawns a standard thread for non-blocking logic execution.
  • Terminal UI: Refresh rate is set to 100ms to balance visual fluidity and CPU overhead.
  • State Management: Uses Option::take() to move closures safely into threads without compromising struct integrity. ? Es ideal para presentar en un portafolio o en el repositorio de hsupport. Si necesitas que agregue una sección de "Troubleshooting" o "Contributing", me dices.