Documentation
¶
Overview ¶
Package compensation provides saga compensation execution.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompensationError ¶
CompensationError wraps an error that occurred during compensation execution.
func (*CompensationError) Error ¶
func (e *CompensationError) Error() string
func (*CompensationError) Unwrap ¶
func (e *CompensationError) Unwrap() error
type CompensationFunc ¶
CompensationFunc is a function that can be executed as compensation. The argument is JSON-encoded data that was passed when registering.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor handles saga compensation execution.
func NewExecutor ¶
NewExecutor creates a new compensation executor.
func (*Executor) AddCompensation ¶
AddCompensation registers a compensation action for an activity. The compensation will be executed in reverse order (LIFO) if the workflow fails.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds registered compensation functions by name.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a new compensation function registry.
func (*Registry) Get ¶
func (r *Registry) Get(name string) (CompensationFunc, bool)
Get retrieves a compensation function by name.
func (*Registry) Register ¶
func (r *Registry) Register(name string, fn CompensationFunc)
Register adds a compensation function to the registry.
type TypedCompensation ¶
TypedCompensation wraps a typed compensation function for registry.
func NewTypedCompensation ¶
func NewTypedCompensation[T any](name string, fn func(ctx context.Context, arg T) error) *TypedCompensation[T]
NewTypedCompensation creates a typed compensation wrapper.
func (*TypedCompensation[T]) AsFunc ¶
func (tc *TypedCompensation[T]) AsFunc() CompensationFunc
AsFunc returns the raw compensation function for direct use.
func (*TypedCompensation[T]) Register ¶
func (tc *TypedCompensation[T]) Register(r *Registry)
Register registers the typed compensation function in the registry.