binding

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 10 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). The engine surfaces this as the start failure or completion failure event depending on which hook returns it.

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

	fx.Provide(
		fx.Annotate(NewDefaultHook, fx.As(new(approval.BusinessBindingHook))),
		NewListener,
	),

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

Module provides the default BusinessBindingHook and starts the Listener that calls WriteBackStatus asynchronously when InstanceCompletedEvent fires. Hosts override the hook with fx.Replace or vef.SupplyBusinessBindingHook.

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 approval.instance.completed 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 NewDefaultHook

func NewDefaultHook() approval.BusinessBindingHook

NewDefaultHook constructs a DefaultHook.

Types

type DefaultHook

type DefaultHook struct{}

DefaultHook writes the final InstanceStatus into the host's business table when Flow.BindingMode == BindingBusiness. It is intentionally minimal: hosts that need transactional outbox writes, multi-column updates, or cross-service calls should supply their own BusinessBindingHook via vef.SupplyBusinessBindingHook(...).

func (*DefaultHook) OnInstanceCreated

func (*DefaultHook) OnInstanceCreated(context.Context, orm.DB, *approval.Flow, *approval.Instance) (string, error)

OnInstanceCreated is a no-op for the default hook — the framework cannot know how to create a business row generically. Hosts override this method to allocate the business primary key. Returning empty string tells the engine to store NULL in Instance.BusinessRecordID.

func (*DefaultHook) WriteBackStatus

func (*DefaultHook) WriteBackStatus(ctx context.Context, db orm.DB, flow *approval.Flow, instance *approval.Instance, finalStatus approval.InstanceStatus) error

WriteBackStatus writes finalStatus to the business table. Skipped when BindingMode != BindingBusiness or when BusinessRecordID is empty (the host never produced one). Misconfigured flows return ErrBindingMisconfigured.

type Listener

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

Listener subscribes to InstanceCompletedEvent and runs the business binding write-back asynchronously, decoupled from the approval transaction.

Failure semantics: if OnInstanceCompleted 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, hook approval.BusinessBindingHook) *Listener

NewListener constructs the listener. The hook is the host-overridable BusinessBindingHook bound via FX (defaults to DefaultHook).

func (*Listener) Start

func (l *Listener) Start() error

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

Jump to

Keyboard shortcuts

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