Skip to content

dfberry/weaver-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weaver

A robust Rust fr### Installation

Add the framework to your Cargo.toml:

[dependencies]
weaver = "0.1.0"

Basic Usage

Here's a simple example of defining and running a workflow:

use weaver::{ving reliable, long-running workflows with a clear separation between orchestration logic and the API layer.

## Overview

Weaver provides a way to define and execute reliable, long-running workflows in Rust. Inspired by concepts from Azure Durable Functions, it supports various workflow patterns but maintains a clear separation of concerns between the orchestration engine and API interfaces.

## Features

- **Separation of Concerns**: Clear division between orchestration logic and API integrations
- **Pattern Support**: Implements all standard Azure Durable Functions patterns:
  - Function Chaining - Sequential execution of steps
  - Fan-out/Fan-in - Parallel execution with aggregated results
  - Async HTTP APIs - Long-running operations with polling
  - Monitoring - Periodic checking of conditions
  - Human Interaction - Workflows that involve human approval steps
  - Aggregator - Collecting and processing events over time
  - Entity Functions - State management for entities

- **Activity System**: Define reusable activities that can be composed into workflows
- **State Management**: Persistence of workflow state with resumability
- **Extensible**: Easy to add new patterns and capabilities

## Getting Started

### Installation

Add the framework to your Cargo.toml:

```toml
[dependencies]
rust-orchestration-framework = "0.1.0"

Basic Usage

Here's a simple example of defining and running a workflow:

use weaver::{
    Activity, ActivityRegistry, OrchestrationEngine, 
    InMemoryStateStore, Workflow
};
use serde_json::json;

// Create and register your activities
let mut registry = ActivityRegistry::new();
registry.register(YourCustomActivity);

// Create the orchestration engine with state storage
let state_store = InMemoryStateStore::new();
let engine = OrchestrationEngine::new(registry, state_store);

// Define a workflow with various patterns
let workflow = Workflow::new("my-workflow", "My First Workflow")
    // Sequential step (Function Chaining)
    .add_step("step1", "YourCustomActivity")
    .with_input("step1", json!({"param": "value"}))
    
    // Parallel steps (Fan-out/Fan-in)
    .add_parallel_step("parallel1", "AnotherActivity", Some("group1"))
    .add_parallel_step("parallel2", "AnotherActivity", Some("group1"))
    
    // Wait for an external event (Human Interaction)
    .add_wait_for_event_step("approval", "ApprovalEvent", Some(3600));

// Start the workflow
let instance_id = engine.start_workflow(workflow).await?;

API Integration

While the orchestration engine is separate from any specific API framework, the library provides helpers for integrating with web APIs:

use weaver::{
    WorkflowApiHandler, OrchestrationEngine, InMemoryStateStore
};

// Create the API handler with the engine
let api_handler = WorkflowApiHandler::new(engine);

// Use the handler in your API routes
let response = api_handler.start_workflow(request).await?;

Patterns

Function Chaining

Sequential execution of functions in a specific order:

let workflow = Workflow::new("sequential", "Sequential Workflow")
    .add_step("step1", "Activity1")
    .add_step("step2", "Activity2")
    .add_step("step3", "Activity3");

Fan-out/Fan-in

Execute multiple functions in parallel and then wait for all to complete:

let workflow = Workflow::new("parallel", "Parallel Workflow")
    .add_parallel_step("p1", "Activity1", Some("group1"))
    .add_parallel_step("p2", "Activity2", Some("group1"))
    .add_parallel_step("p3", "Activity3", Some("group1"));

Async HTTP APIs

Coordinate long-running operations with polling:

let workflow = Workflow::new("async-http", "Async HTTP Workflow")
    .add_async_http_step(
        "start-operation", 
        "HttpStartActivity",
        Some("https://example.com/status"),
        Some(5) // Poll every 5 seconds
    );

Monitoring

Recurring process in a workflow that polls until conditions are met:

let workflow = Workflow::new("monitor", "Monitoring Workflow")
    .add_monitor_step(
        "check-condition", 
        "ConditionCheckActivity",
        10, // Check every 10 seconds
        Some(3600) // Timeout after 1 hour
    );

Human Interaction

Involve human approval in an automated process:

let workflow = Workflow::new("approval", "Approval Workflow")
    .add_step("start", "StartActivity")
    .add_wait_for_event_step("get-approval", "ApprovalEvent", Some(86400))
    .add_step("complete", "CompleteActivity");

Aggregator

Aggregate event data over a period into a single entity:

let workflow = Workflow::new("aggregator", "Aggregator Workflow")
    .add_aggregation_step(
        "collect-events",
        "ProcessEvents",
        vec!["Event1".to_string(), "Event2".to_string()],
        3600 // Collect for 1 hour
    );

Entity Functions

Manage the state of a small entity with operations:

let workflow = Workflow::new("entity", "Entity Workflow")
    .add_entity_step("counter", "counter-entity", "increment")
    .add_entity_step("get-counter", "counter-entity", "get");

License

MIT

  • Orchestration Engine: A robust engine to manage the execution of workflows, including starting, stopping, and monitoring orchestration instances.
  • Activity Definitions: Define reusable activities that can be executed within workflows.
  • State Management: Keep track of the state of orchestration instances, including their current status and relevant data.

Usage

To use the Rust Orchestration Framework, include it as a dependency in your Cargo.toml file:

[dependencies]
rust-orchestration-framework = { path = "path/to/rust-orchestration-framework" }

Example Workflow

You can define a simple workflow by creating a new Rust file in the examples directory. Refer to examples/simple_workflow.rs for a demonstration of how to implement a basic workflow using the framework.

API Integration

To trigger workflows via API calls, check out examples/api_integration.rs, which shows how to integrate the orchestration framework with an API layer.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests. Ensure that your code adheres to the project's coding standards and includes appropriate tests.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Releases

No releases published

Packages

No packages published