rely

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 4 Imported by: 0

README

rely

rely is a lightweight, durable execution engine for Go. It allows you to define workflows that can survive crashes and restarts by replaying history from a journal.

Installation

go get github.com/exeebit/rely

Usage

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/exeebit/rely"
	"github.com/exeebit/rely/journal"
)

func main() {
	// 1. Initialize Journal
	j := journal.NewMemoryJournal()
	engine := rely.New(j)

	// 2. Define Workflow
	workflow := engine.Define("MyWorkflow", func(ctx rely.Context, args ...interface{}) error {
		var result string
		// Define a durable step
		if err := ctx.Step("Step1", func() (interface{}, error) {
			return "done", nil
		}).Result(&result); err != nil {
			return err
		}
		fmt.Println("Result:", result)
		return nil
	})

	// 3. Execute
	if err := workflow.Execute(context.Background(), "arg1"); err != nil {
		log.Fatal(err)
	}
}

Features

  • Durable Steps: Steps are executed once and their results are persisted.
  • Journaling: Pluggable journal backend (currently supports in-memory).
  • Replay: Automatically restores state on restart.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	context.Context

	// Step executes a unit of work durably.
	// name: Unique identifier for the step within the workflow.
	// fn: The function to execute. Must return (result, error).
	Step(name string, fn func() (interface{}, error), opts ...StepOption) StepResult
}

Context wraps standard context and adds durable execution capabilities.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine manages the durable execution.

func New

func New(j journal.Journal) *Engine

New creates a new Engine with the given journal backend.

func (*Engine) Define

func (e *Engine) Define(name string, fn WorkflowFunc) *Workflow

Define registers a workflow definition.

type ResultContainer

type ResultContainer struct {
	Value interface{}
	Err   error
}

ResultContainer is a helper to unmarshal step results.

type Step

type Step struct {
	Name string
	Fn   func() error
}

Step represents a unit of execution.

type StepConfig

type StepConfig struct {
	MaxRetries int
}

type StepOption

type StepOption func(*StepConfig)

StepOption allows configuring a step (e.g., retries).

func Retry

func Retry(times int) StepOption

type StepResult

type StepResult interface {
	// Result unmarshals the success value into target (pointer).
	Result(target interface{}) error
	// Err returns the error if the step failed.
	Err() error
}

StepResult allows retrieving the result of a step or its error.

type Workflow

type Workflow struct {
	// contains filtered or unexported fields
}

func (*Workflow) Execute

func (w *Workflow) Execute(ctx context.Context, args ...interface{}) error

Execute starts or follows a workflow execution.

type WorkflowFunc

type WorkflowFunc func(ctx Context, input ...interface{}) error

WorkflowFunc is the function signature for a workflow.

Directories

Path Synopsis
examples
basic command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL