binding

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBindingMisconfigured = errors.New("approval: business binding misconfigured")

ErrBindingMisconfigured signals that a Flow with BindingMode=business is missing one of the required columns (business_table / business_pk_field / business_status_field), carries an unsafe identifier, or resolved to an empty record id. The Listener acknowledges instead of retrying: a misconfiguration does not heal by retry.

View Source
var Module = fx.Module(
	"vef:approval:binding",

	fx.Provide(
		NewNoopRefProvider,
		NewIdentityResolver,
		NewWriter,
		NewListener,
	),

	fx.Invoke(func(l *Listener) error { return l.Start() }),
)

Module provides the engine-owned write-back Writer (with its default no-op BusinessRefProvider and identity BusinessRefResolver) and starts the Listener that runs the asynchronous write-back legs when the completed / returned / withdrawn / resubmitted instance events fire. (The started leg is invoked synchronously by the start_instance command inside its transaction.) Hosts replace the provider / resolver via vef.SupplyBusinessRefProvider / vef.SupplyBusinessRefResolver; the Writer itself is not an extension point.

Reliability note: the Listener is best-effort under the default in-memory event transport — a process crash between event publication and listener execution drops the write-back. Production deployments that rely on business-table consistency MUST route the approval.* instance events through the framework's outbox transport so the listener retries until acknowledged. The Listener publishes InstanceBindingFailedEvent on persistent failure so operators / saga workers can compensate; misconfigured flows (ErrBindingMisconfigured) ack immediately to avoid an infinite retry loop.

Functions

func NewIdentityResolver added in v0.35.0

func NewIdentityResolver() approval.BusinessRefResolver

NewIdentityResolver constructs the default identity resolver.

func NewNoopRefProvider added in v0.35.0

func NewNoopRefProvider() approval.BusinessRefProvider

NewNoopRefProvider constructs the default no-op provider.

Types

type Listener

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

Listener subscribes to the instance-lifecycle events that drive the asynchronous legs of the engine-owned business write-back — completed, returned, withdrawn, resubmitted — decoupled from the approval transaction. (The started leg runs synchronously inside the start_instance transaction and never reaches this listener.)

Failure semantics: if the write-back returns an error, the listener publishes InstanceBindingFailedEvent so operators (or compensating workers) can retry. The approval status itself is never rolled back — the workflow has already decided.

func NewListener

func NewListener(db orm.DB, bus event.Bus, writer *Writer) *Listener

NewListener constructs the listener around the engine-owned Writer.

func (*Listener) Start

func (l *Listener) Start() error

Start registers the event subscriptions. Called by FX Invoke during boot.

type Writer added in v0.35.0

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

Writer performs the engine-owned write-back of instance state onto the host's business table when Flow.BindingMode == BindingBusiness. It is not an extension point: hosts influence which row it targets through approval.BusinessRefResolver and extend around it with lifecycle hooks or event subscriptions, but the write-back itself belongs to the engine.

func NewWriter added in v0.35.0

func NewWriter(resolver approval.BusinessRefResolver) *Writer

NewWriter constructs the Writer around the ref resolver.

func (*Writer) WriteBack added in v0.37.0

func (w *Writer) WriteBack(ctx context.Context, db orm.DB, flow *approval.Flow, instance *approval.Instance, trigger approval.BindingTrigger) error

WriteBack projects the instance's current state onto the business table, targeting the row whose pk column matches the resolved BusinessRef. The trigger selects which columns are written (see approval.BindingTrigger for the linkage matrix); the status column is always written, the optional instance-id / started-at / finished-at columns only when the flow configures them. Skipped when the flow is not business-bound or the instance carries no BusinessRef. Misconfigured flows return ErrBindingMisconfigured; resolver failures propagate as transient errors so the outbox can retry.

Jump to

Keyboard shortcuts

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