Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
NewListener constructs the listener. The hook is the host-overridable BusinessBindingHook bound via FX (defaults to DefaultHook).