workflow

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package workflow is the workflow tier: the one boundary observed in every environment and the only tier that opens a transaction. A consumer's workflow embeds a Base built from its contract and runs each contract method in one of three shapes: a read (Exec, no transaction), a command (ExecTx, one transaction) or a saga (Exec whose body commits each local step with InTx).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tier added in v0.0.7

func Tier() decorate.Tier

Tier is the workflow tier's decoration: recovery → logging → tracing → metrics → timeout, outermost first.

Types

type Base added in v0.0.7

type Base struct {

	// Subject runs the workflow's operations through the tier; it supplies Name and Exec.
	decorate.Subject
	// contains filtered or unexported fields
}

Base is the embeddable core of a workflow named by its Subject: Name and Exec (a read or a saga) are promoted from the Subject, ExecTx runs a command and InTx a saga's local step. Each operation is one method of the workflow's contract, decorated as the component's name plus the method's snake_case name. The zero Base runs reads undecorated and refuses every transaction.

func NewBase added in v0.0.7

func NewBase[W any](
	decs decorate.Decorations,
	name string,
	tx interfaces.TransactionManager,
) (Base, error)

NewBase builds the Base for the workflow named name over tx (needed only by ExecTx and InTx), decorated from decs: one chain per method of the contract W, each resolved as the workflow-tier component name+"."+op, so the config can tune the workflow or one of its operations. A W that is not an interface, or a decoration that fails to resolve, is an error.

func (Base) ExecTx added in v0.0.10

func (b Base) ExecTx[R any](
	ctx context.Context,
	op string,
	fn func(context.Context) (R, error),
) (R, error)

ExecTx runs fn as the command op: one decorated operation whose body runs in one transaction, which commits when fn succeeds and rolls back when it fails. Every store call fn makes joins the transaction through the context. The body's error, or the commit's, is returned with its code intact and a zero result, so a result whose transaction did not commit never reaches the caller.

func (Base) InTx added in v0.0.10

func (b Base) InTx[R any](
	ctx context.Context,
	fn func(context.Context) (R, error),
) (R, error)

InTx runs fn in one transaction, undecorated: a saga's local step, inside the one decorated operation (Exec) that runs the saga, committing a write between remote calls or compensating one. A context already in a transaction, or a Base with no transaction manager, fails INTERNAL without running fn: a transaction never opens inside another.

func (Base) Pass added in v0.0.10

func (b Base) Pass(
	op string,
	pass interfaces.Workflow[struct{}, struct{}],
) interfaces.Workflow[struct{}, struct{}]

Pass runs a background loop's pass as the operation op (its loop's name) on the workflow's own decoration, with no transaction: a pass that writes commits each write with InTx. Its method value is a loop.Decorator, so every pass is logged, counted, traced and recovered like a request.

type Entity added in v0.0.16

type Entity[T, P any, ID comparable, N any] struct {
	// Entity serves the roles.
	decorate.Entity[T, P, ID]

	// Base runs the workflow's operations and supplies Name, Exec, ExecTx and InTx.
	Base
	// contains filtered or unexported fields
}

Entity is the workflow-tier entity base: a Base that also serves the entity's roles over N, the next tier's contract (a pipeline). A read runs as one operation with no transaction, and every write (Create, Update, Delete, Insert, Upsert, PurgeBefore) as one command in its own transaction. A workflow embeds it and adds its product operations through Exec, ExecTx or InTx, calling Next.

func NewEntity added in v0.0.16

func NewEntity[W, T, P any, ID comparable, N any](
	decs decorate.Decorations,
	name string,
	tx interfaces.TransactionManager,
	next N,
) (Entity[T, P, ID, N], error)

NewEntity builds the Entity of the workflow named name over next, whose contract is W (an interface), serving the roles W has from next's methods and committing each write through tx: decorated as NewBase decorates. A role W names that next lacks is CodeInternal.

func (Entity[T, P, ID, N]) Next added in v0.0.16

func (e Entity[T, P, ID, N]) Next() N

Next returns the pipeline the workflow is built over, as its contract declares it.

Jump to

Keyboard shortcuts

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