compensation

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package compensation provides compensation (rollback) activities for workflow steps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIRollbackHandler

type APIRollbackHandler interface {
	RollbackAPI(ctx context.Context, input APIRollbackInput) error
}

APIRollbackHandler handles external API call rollbacks.

type APIRollbackInput

type APIRollbackInput struct {
	RollbackInput
	Endpoint         string            `json:"endpoint"`
	Method           string            `json:"method"`
	RequestID        string            `json:"requestId,omitempty"`
	CompensateURL    string            `json:"compensateUrl,omitempty"`
	CompensateMethod string            `json:"compensateMethod,omitempty"`
	Headers          map[string]string `json:"headers,omitempty"`
}

APIRollbackInput for compensating external API calls.

type AgentRollbackHandler

type AgentRollbackHandler interface {
	RollbackAgent(ctx context.Context, input AgentRollbackInput) error
}

AgentRollbackHandler handles agent execution rollbacks.

type AgentRollbackInput

type AgentRollbackInput struct {
	RollbackInput
	AgentType  string          `json:"agentType"`
	AgentName  string          `json:"agentName"`
	OutputPath string          `json:"outputPath,omitempty"`
	Output     json.RawMessage `json:"output,omitempty"`
}

AgentRollbackInput for undoing agent execution side effects.

type CompensationActivities

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

CompensationActivities holds compensation activity implementations.

func NewCompensationActivities

func NewCompensationActivities(
	agentHandler AgentRollbackHandler,
	fileHandler FileRollbackHandler,
	apiHandler APIRollbackHandler,
	notifHandler NotificationRollbackHandler,
	dbHandler DatabaseRollbackHandler,
) *CompensationActivities

NewCompensationActivities creates a new CompensationActivities instance.

func NewDefaultCompensationActivities

func NewDefaultCompensationActivities() *CompensationActivities

NewDefaultCompensationActivities creates CompensationActivities with all default handlers.

func (*CompensationActivities) RollbackAgentExecution

func (ca *CompensationActivities) RollbackAgentExecution(ctx context.Context, input AgentRollbackInput) (RollbackOutput, error)

RollbackAgentExecution undoes agent execution side effects.

func (*CompensationActivities) RollbackDatabaseOperation

func (ca *CompensationActivities) RollbackDatabaseOperation(ctx context.Context, input DatabaseRollbackInput) (RollbackOutput, error)

RollbackDatabaseOperation undoes database changes.

func (*CompensationActivities) RollbackExternalAPICall

func (ca *CompensationActivities) RollbackExternalAPICall(ctx context.Context, input APIRollbackInput) (RollbackOutput, error)

RollbackExternalAPICall compensates external API calls.

func (*CompensationActivities) RollbackFileOperation

func (ca *CompensationActivities) RollbackFileOperation(ctx context.Context, input FileRollbackInput) (RollbackOutput, error)

RollbackFileOperation undoes file creation/modification.

func (*CompensationActivities) RollbackNotification

func (ca *CompensationActivities) RollbackNotification(ctx context.Context, input NotificationRollbackInput) (RollbackOutput, error)

RollbackNotification cancels scheduled notifications.

type DatabaseRollbackHandler

type DatabaseRollbackHandler interface {
	RollbackDatabase(ctx context.Context, input DatabaseRollbackInput) error
}

DatabaseRollbackHandler handles database rollbacks.

type DatabaseRollbackInput

type DatabaseRollbackInput struct {
	RollbackInput
	Collection   string          `json:"collection"`
	DocumentID   string          `json:"documentId"`
	Operation    string          `json:"operation"` // "insert", "update", "delete"
	PreviousData json.RawMessage `json:"previousData,omitempty"`
}

DatabaseRollbackInput for undoing database changes.

type DefaultAPIRollbackHandler

type DefaultAPIRollbackHandler struct{}

DefaultAPIRollbackHandler provides default API rollback implementation.

func NewDefaultAPIRollbackHandler

func NewDefaultAPIRollbackHandler() *DefaultAPIRollbackHandler

NewDefaultAPIRollbackHandler creates a new DefaultAPIRollbackHandler.

func (*DefaultAPIRollbackHandler) RollbackAPI

func (h *DefaultAPIRollbackHandler) RollbackAPI(ctx context.Context, input APIRollbackInput) error

RollbackAPI sends compensation request to external API.

type DefaultAgentRollbackHandler

type DefaultAgentRollbackHandler struct{}

DefaultAgentRollbackHandler provides default agent rollback implementation.

func NewDefaultAgentRollbackHandler

func NewDefaultAgentRollbackHandler() *DefaultAgentRollbackHandler

NewDefaultAgentRollbackHandler creates a new DefaultAgentRollbackHandler.

func (*DefaultAgentRollbackHandler) RollbackAgent

RollbackAgent cleans up agent execution artifacts.

type DefaultDatabaseRollbackHandler

type DefaultDatabaseRollbackHandler struct{}

DefaultDatabaseRollbackHandler provides default database rollback implementation.

func NewDefaultDatabaseRollbackHandler

func NewDefaultDatabaseRollbackHandler() *DefaultDatabaseRollbackHandler

NewDefaultDatabaseRollbackHandler creates a new DefaultDatabaseRollbackHandler.

func (*DefaultDatabaseRollbackHandler) RollbackDatabase

RollbackDatabase reverts database changes.

type DefaultFileRollbackHandler

type DefaultFileRollbackHandler struct{}

DefaultFileRollbackHandler provides default file rollback implementation.

func NewDefaultFileRollbackHandler

func NewDefaultFileRollbackHandler() *DefaultFileRollbackHandler

NewDefaultFileRollbackHandler creates a new DefaultFileRollbackHandler.

func (*DefaultFileRollbackHandler) RollbackFile

RollbackFile restores files to their original state.

type DefaultNotificationRollbackHandler

type DefaultNotificationRollbackHandler struct{}

DefaultNotificationRollbackHandler provides default notification rollback implementation.

func NewDefaultNotificationRollbackHandler

func NewDefaultNotificationRollbackHandler() *DefaultNotificationRollbackHandler

NewDefaultNotificationRollbackHandler creates a new DefaultNotificationRollbackHandler.

func (*DefaultNotificationRollbackHandler) RollbackNotification

RollbackNotification cancels or revokes notifications.

type FileRollbackHandler

type FileRollbackHandler interface {
	RollbackFile(ctx context.Context, input FileRollbackInput) error
}

FileRollbackHandler handles file operation rollbacks.

type FileRollbackInput

type FileRollbackInput struct {
	RollbackInput
	FilePath        string          `json:"filePath"`
	Operation       string          `json:"operation"` // "create", "update", "delete"
	OriginalContent json.RawMessage `json:"originalContent,omitempty"`
	BackupPath      string          `json:"backupPath,omitempty"`
}

FileRollbackInput for undoing file operations.

type NotificationRollbackHandler

type NotificationRollbackHandler interface {
	RollbackNotification(ctx context.Context, input NotificationRollbackInput) error
}

NotificationRollbackHandler handles notification rollbacks.

type NotificationRollbackInput

type NotificationRollbackInput struct {
	RollbackInput
	NotificationType string   `json:"notificationType"` // "email", "webhook", "sms"
	NotificationID   string   `json:"notificationId"`
	Recipients       []string `json:"recipients,omitempty"`
}

NotificationRollbackInput for canceling scheduled notifications.

type RollbackInput

type RollbackInput struct {
	WorkflowID   string            `json:"workflowId"`
	ActivityName string            `json:"activityName"`
	ResourceID   string            `json:"resourceId,omitempty"`
	ResourceType string            `json:"resourceType,omitempty"`
	Metadata     map[string]string `json:"metadata,omitempty"`
	OriginalData json.RawMessage   `json:"originalData,omitempty"`
}

RollbackInput provides context for rollback operations.

type RollbackOutput

type RollbackOutput struct {
	Success  bool   `json:"success"`
	Message  string `json:"message,omitempty"`
	Error    string `json:"error,omitempty"`
	Rollback bool   `json:"rollback"` // Indicates this was a rollback operation
}

RollbackOutput provides the result of a rollback operation.

Jump to

Keyboard shortcuts

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