Skip to main content

Crate fusee

Crate fusee 

Expand description

§Fusee

Durable execution at the speed of the disk. Workflows are ordinary async Rust; each step’s result is appended to a per-shard log, one fdatasync covers every record that arrived in the meantime, and the next step starts as soon as its input is durable. Code runs ahead of the disk; only work that leaves the process waits, and only for the records it depends on.

use fusee::{Config, Engine, Error, RetryPolicy, Signal, WorkflowRef};
use std::time::Duration;

pub const CHECKOUT: WorkflowRef<u64, String> = WorkflowRef::new("checkout");
pub const REVIEW: Signal<bool> = Signal::new("review");

let engine = Engine::open(Config::local("./data")).await?;
engine.register(CHECKOUT, |ctx, order: u64| async move {
    let quote: u64 = ctx.step("quote", || async move { Ok::<_, Error>(order * 2) }).await?;
    let id: String = ctx
        .step("charge", || charge(quote, ctx.key()))
        .retry(RetryPolicy::attempts(5))
        .await?;
    match ctx.wait_for(REVIEW).timeout(Duration::from_secs(86_400)).await? {
        Some(true) => Ok(id),
        _ => ctx.step("refund", || async { Ok::<_, Error>(String::new()) }).await,
    }
});
let run = engine.start(CHECKOUT, "order-123", &21).await?;
run.signal(REVIEW, &true).await?;
println!("{}", run.result().await?);

Options are builder methods on the operation, then .await: a step’s .retry(..), .timeout(..), .read_only(), .limit(..); a wait’s .timeout(..); a start’s .id_policy(..), .timeout(..); an update’s or call’s .id(..). A step’s error is anything that converts into a Failure (every error type does); return Failure::fatal to fail without retries.

§Guarantees

  • An acknowledged start, signal or step result is never lost within the durability mode’s failure model.
  • A recorded step result never changes, and code after it sees the same value on every run.
  • A step’s function runs at least once. It runs again only if the process failed before that step’s result became durable. Ctx::key returns a stable key; pass it to services that accept idempotency keys to make the effect exactly once.
  • Nothing leaves the process based on state a crash could take back.

Re-exports§

pub use codec::Codec;
pub use codec::aes_gcm;
pub use ctx::ChildOptions;
pub use ctx::Completion;
pub use ctx::Ctx;
pub use ctx::Exhausted;
pub use ctx::RetryPolicy;
pub use ctx::StepOptions;
pub use ctx::WaitOptions;
pub use ctx::WorkflowLog;
pub use defs::AsQuery;
pub use defs::AsSignal;
pub use defs::AsUpdate;
pub use defs::AsWorkflow;
pub use defs::Op;
pub use defs::Query;
pub use defs::Signal;
pub use defs::Update;
pub use defs::WorkflowRef;
pub use dev::Profile;
pub use engine::Config;
pub use engine::Durability;
pub use engine::Engine;
pub use engine::EventOptions;
pub use engine::RunHandle;
pub use engine::ScheduleHandle;
pub use engine::StartOptions;
pub use engine::UpdateOptions;
pub use error::Error;
pub use error::Result;
pub use export::ReplayReport;
pub use export::Replayer;
pub use failure::Failure;
pub use failure::FailureData;
pub use failure::IntoFailure;
pub use limits::LimitInfo;
pub use limits::LimitSpec;
pub use limits::Priority;
pub use object::CallOptions;
pub use object::Object;
pub use object::ObjectCall;
pub use object::ObjectCtx;
pub use object::ObjectHandlers;
pub use object::ObjectRef;
pub use object::ObjectType;
pub use object::State;
pub use queue::Batch;
pub use queue::Debounce;
pub use queue::Receipt;
pub use schedule::Overlap;
pub use schedule::ScheduleSpec;
pub use stream::Chunk;
pub use stream::ChunkValue;
pub use stream::StreamBatch;
pub use stream::StreamEnd;
pub use stream::StreamReader;
pub use stream::StreamWriter;
pub use fusee_core as core;

Modules§

audit
Audit: who asked for a signal, cancel, terminate or reset.
backup
Continuous backup of a local data directory to object storage, and restore to a point in time.
codec
Payload codecs: encryption applied inside the application before payloads become records.
concurrency
Runs at once per type or key: at most limit runs of a workflow type (or of one key of it, a tenant say) run at a time; the others wait, in the order they were started, and show as queued.
ctx
The workflow context: what workflow code uses to make durable progress.
defs
Typed references: a workflow type, signal, query or update named once, as a const, with the types of what it carries.
delay
Delayed start: engine.start(wf, id, &input).delay(d) (or .at(t)).
dev
The dev profile: for writing workflows, not for production.
engine
The embedded engine: one thread per shard, each running a [ShardRuntime] inside a single-threaded Tokio runtime so step functions can use Tokio I/O.
error
export
Exported journals and replay testing.
failure
A failure as recorded: what a failed attempt, step, update, object call or workflow carries, in every SDK.
http
Fusee’s HTTP API: /v1, JSON, server-sent events for run changes and streams, an OpenAPI document, Prometheus metrics, and the web UI.
limits
Concurrency and rate limits for steps.
log
Logs: the workflow’s (Ctx::log) and the engine’s own warnings, through one hook.
object
Keyed objects: handlers per key with key/value state, built from Fusee’s records.
queue
Debounce and batching: starts sent under one key become one run.
reshard
Changes the shard count of a closed local data directory, offline (fusee reshard <dir> <shards>; design and invariants in docs/operations.md, “Changing the shard count”).
schedule
Schedules: runs started on a cron expression or a fixed interval.
stream
Durable streams: chunks a run appends to a named stream (tokens from a model, progress events) and readers that follow them from an offset.
upgrade
Converts a data directory from log format 2 (a log per shard) to log format 3 (one shared log, [crate::wal]), offline.

Structs§

IdPolicy
Workflow ID reuse rules for a start. Recorded with the start.
LocalOptions
Metrics
Counters, per shard. Cheap to copy; exported by the engine.
RunDetail
RunSummary

Enums§

FlushMethod
How a batch is made durable.
OnFinished
What a start does when the workflow ID’s last run finished within retention.
OnRunning
What a start does when the workflow ID is already running.
ParentClose
What happens to a child workflow when its parent closes.
Preallocate
How new segment files are prepared.