selvedge

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package selvedge binds typed activities and durable workflows to Selvedge. Producer and Worker own their private handles and lifecycle; New(app) retains the caller-owned native path. Selvedge owns persistence, dispatch and codecs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotRunning means the role cannot admit operations in its current state.
	ErrNotRunning = errors.New("selvedge: workflow role is not running")
	// ErrRegistrationSealed means the role has left its initial registration state.
	ErrRegistrationSealed = errors.New("selvedge: workflow registration is sealed")
	// ErrShutdownIncomplete means this caller stopped waiting; cleanup continues.
	ErrShutdownIncomplete = errors.New("selvedge: workflow shutdown wait interrupted")
	// ErrInputEncoding rejects input before insertion, including unstable or invalid UTF-8 JSON.
	ErrInputEncoding = errors.New("selvedge: invalid workflow input encoding")
)

Functions

func Declare

func Declare[I, O any](r Role, wf execution.Workflow[I, O]) error

Declare records the workflow's name and exact input/output types before Start. Repeating the same contract is idempotent; name/type collisions are errors.

func Register

func Register[I, O any](activities *Activities, activity execution.Activity[I, O], handler func(context.Context, I) (O, error), options sv.ActivityOptions) error

Register installs a typed activity with native Selvedge options and codecs. Its generic signature preserves the input and output types for Selvedge; Activities therefore does not implement execution.ActivityRegistrar.

func RegisterWorkflow

func RegisterWorkflow[I, O any](w *Worker, wf execution.Workflow[I, O], fn func(*sv.WorkflowContext, I) (O, error)) error

RegisterWorkflow declares and installs one worker-owned native workflow.

Types

type Activities

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

Activities registers named handlers on one Selvedge app. A Worker-owned registry shares its registration gate; New(app) retains caller ownership.

func New

func New(app *sv.App) (*Activities, error)

New binds activity registration to app without starting or stopping it.

func (*Activities) Scope

Scope binds execution to ctx, including its cancellation and detached-scope behavior. The context.Context arguments of execution calls do not replace this native workflow context. Futures retain the scope that scheduled them.

type Admission

type Admission struct {
	// ID is the caller-chosen durable instance identifier.
	ID string
	// Created reports that this call inserted the job, rather than reconciled it.
	Created bool
}

Admission identifies an existing or newly inserted durable job.

func Submit

func Submit[I, O any](ctx context.Context, r Role, wf execution.Workflow[I, O], id string, in I) (Admission, error)

Submit encodes input once and inserts or reconciles the caller-chosen ID. Every outcome describes this call; earlier uncertain attempts may still exist.

type AdmissionConflictError

type AdmissionConflictError struct {
	// ID is the occupied instance ID.
	ID string
	// Workflow is the requested workflow name.
	Workflow string
	// ExistingWorkflow is the persisted workflow name.
	ExistingWorkflow string
	// InputDiffers reports unequal frozen encoded input bytes.
	InputDiffers bool
	// ChildInstance reports persisted parent identity rather than a root job.
	ChildInstance bool
	// ExistingInput is a copy of stored bytes for prior-attempt reconciliation.
	ExistingInput []byte
}

AdmissionConflictError reports an existing job with a different identity. ExistingInput can match a prior uncertain attempt; conflict alone does not prove that the caller's logical request was never admitted.

func (*AdmissionConflictError) Error

func (e *AdmissionConflictError) Error() string

Error describes the conflicting identity without including encoded input.

func (*AdmissionConflictError) Unwrap

func (e *AdmissionConflictError) Unwrap() error

Unwrap makes a conflict match the native duplicate-instance sentinel.

type AdmissionUncertainError

type AdmissionUncertainError struct {
	// ID is the caller-chosen instance ID to reuse on retry.
	ID string
	// Input is a copy of this call's frozen bytes, not a fresh encoding.
	Input []byte
	// Err is the native admission or reconciliation-read failure.
	Err error
}

AdmissionUncertainError means this call may have committed Input under ID. Retain Input across retries; a later rejected call does not prove absence.

func (*AdmissionUncertainError) Error

func (e *AdmissionUncertainError) Error() string

Error describes uncertain admission without including input bytes or error details.

func (*AdmissionUncertainError) Unwrap

func (e *AdmissionUncertainError) Unwrap() error

Unwrap preserves the native admission or read failure for errors.Is/As.

type Job

type Job[O any] struct {
	// ID identifies the durable instance.
	ID string
	// State is the native Running, Completed, Failed or Cancelled status.
	State sv.WorkflowStatus
	// Output is the decoded completed result; other states leave its zero value.
	Output O
	// Err is the recorded failure for Failed or Cancelled, not a lookup error.
	Err error
	// StartedAt records native admission time.
	StartedAt time.Time
	// UpdatedAt records the identity snapshot's last native update time.
	UpdatedAt time.Time
}

Job is a typed snapshot. Output is meaningful only in the Completed state.

func Lookup

func Lookup[I, O any](ctx context.Context, r Role, wf execution.Workflow[I, O], id string) (Job[O], error)

Lookup checks workflow identity before decoding the native typed result. Native missing-instance and decoding errors are lookup errors, not Job.Err.

type Producer

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

Producer owns a producer-only native handle. Declare contracts before Start. Its zero value is unusable; construct it with NewProducer.

func NewProducer

func NewProducer(opts ...ProducerOption) (*Producer, error)

NewProducer configures an owned producer without opening storage until Start.

func (*Producer) Ready

func (p *Producer) Ready() error

Ready reports lifecycle readiness, not database connectivity.

func (*Producer) Shutdown

func (p *Producer) Shutdown(ctx context.Context) error

Shutdown drains admitted calls and waits for cleanup; ctx bounds only this wait.

func (*Producer) Start

func (p *Producer) Start(ctx context.Context) error

Start initializes producer storage. Cancelling ctx after success does not close it.

type ProducerOption

type ProducerOption = sv.Option

ProducerOption configures native producer storage, migration and notifications. Native worker options are ignored; client observability wraps operations.

type Role

type Role interface {
	// contains filtered or unexported methods
}

Role is a producer or worker with a private native handle and one lifecycle.

type Worker

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

Worker owns a native worker and its workflow and activity registrations. Its zero value is unusable; construct it with NewWorker.

func NewWorker

func NewWorker(opts ...sv.Option) (*Worker, error)

NewWorker configures an owned worker without starting execution until Start.

func (*Worker) Activities

func (w *Worker) Activities() *Activities

Activities returns the registry sharing this worker's registration lifecycle.

func (*Worker) Ready

func (w *Worker) Ready() error

Ready reports lifecycle readiness, not database connectivity.

func (*Worker) Shutdown

func (w *Worker) Shutdown(ctx context.Context) error

Shutdown drains admitted calls and waits for native cleanup without stopping other waiters.

func (*Worker) Start

func (w *Worker) Start(ctx context.Context) error

Start initializes storage and starts the registered worker execution loops.

Directories

Path Synopsis
examples
durable/contract
Package contract contains the application-owned metadata job shared by binaries.
Package contract contains the application-owned metadata job shared by binaries.
durable/producer command
Command producer submits or inspects an object-metadata job without running it.
Command producer submits or inspects an object-metadata job without running it.
durable/worker command
Command worker executes the application's object-metadata jobs.
Command worker executes the application's object-metadata jobs.

Jump to

Keyboard shortcuts

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