recovery

package
v0.0.0-...-c1e920f Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package recovery provides infrastructure helpers for wiring up recovery in the main application

Package recovery provides generic infrastructure recovery mechanisms for PromptPipe to handle application restarts gracefully. This package is application-agnostic and provides interfaces for flows to register their own recovery logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateResponseHandlerRecoveryHandler

func CreateResponseHandlerRecoveryHandler(callback ResponseHandlerRecoveryCallback) func(ResponseHandlerRecoveryInfo) error

CreateResponseHandlerRecoveryHandler returns a simple handler that delegates to the provided callback

func TimerRecoveryHandler

func TimerRecoveryHandler(timer models.Timer) func(TimerRecoveryInfo) (string, error)

TimerRecoveryHandler provides the callback function for timer recovery infrastructure. NOTE: This creates timers with DUMMY CALLBACKS that only log - they do NOT restore business logic. For timers that need business logic (like daily prompt reminders), the owning component (e.g., SchedulerTool) should handle recovery directly by rescheduling timers with proper callbacks after initialization. This generic handler is only useful for simple timeout-based state transitions where the timeout itself doesn't need to trigger specific business actions.

Types

type ParticipantRecoverable

type ParticipantRecoverable interface {
	Recoverable
	// RecoverParticipant is called for each active participant of this flow type
	RecoverParticipant(ctx context.Context, participantID string, participant interface{}, registry *RecoveryRegistry) error
	// GetFlowType returns the flow type this recoverable handles
	GetFlowType() models.FlowType
}

ParticipantRecoverable defines recovery for participant-based flows

type Recoverable

type Recoverable interface {
	// RecoverState is called during application startup to restore component state
	RecoverState(ctx context.Context, registry *RecoveryRegistry) error
}

Recoverable defines the interface for components that can recover their state

type RecoveryManager

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

RecoveryManager orchestrates recovery of all registered components

func NewRecoveryManager

func NewRecoveryManager(store store.Store, timer models.Timer) *RecoveryManager

NewRecoveryManager creates a new recovery manager

func (*RecoveryManager) GetRegistry

func (rm *RecoveryManager) GetRegistry() *RecoveryRegistry

GetRegistry provides access to the recovery registry for infrastructure setup

func (*RecoveryManager) RecoverAll

func (rm *RecoveryManager) RecoverAll(ctx context.Context) error

RecoverAll performs recovery of all registered components

func (*RecoveryManager) RegisterHandlerRecovery

func (rm *RecoveryManager) RegisterHandlerRecovery(fn func(ResponseHandlerRecoveryInfo) error)

RegisterHandlerRecovery registers the response handler recovery infrastructure

func (*RecoveryManager) RegisterRecoverable

func (rm *RecoveryManager) RegisterRecoverable(r Recoverable)

RegisterRecoverable adds a component that can be recovered

func (*RecoveryManager) RegisterTimerRecovery

func (rm *RecoveryManager) RegisterTimerRecovery(fn func(TimerRecoveryInfo) (string, error))

RegisterTimerRecovery registers the timer recovery infrastructure

type RecoveryRegistry

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

RecoveryRegistry provides services that components can use during recovery

func NewRecoveryRegistry

func NewRecoveryRegistry(store store.Store, timer models.Timer) *RecoveryRegistry

NewRecoveryRegistry creates a new recovery registry

func (*RecoveryRegistry) GetStore

func (r *RecoveryRegistry) GetStore() store.Store

GetStore provides access to the store for recovery operations

func (*RecoveryRegistry) GetTimer

func (r *RecoveryRegistry) GetTimer() models.Timer

GetTimer provides access to the timer for recovery operations

func (*RecoveryRegistry) RecoverResponseHandler

func (r *RecoveryRegistry) RecoverResponseHandler(info ResponseHandlerRecoveryInfo) error

RecoverResponseHandler requests recovery of a response handler

func (*RecoveryRegistry) RecoverTimer

func (r *RecoveryRegistry) RecoverTimer(info TimerRecoveryInfo) (string, error)

RecoverTimer requests recovery of a timer

func (*RecoveryRegistry) RegisterHandlerRecovery

func (r *RecoveryRegistry) RegisterHandlerRecovery(fn func(ResponseHandlerRecoveryInfo) error)

RegisterHandlerRecovery registers a callback for response handler recovery

func (*RecoveryRegistry) RegisterTimerRecovery

func (r *RecoveryRegistry) RegisterTimerRecovery(fn func(TimerRecoveryInfo) (string, error))

RegisterTimerRecovery registers a callback for timer recovery

type ResponseHandlerRecoveryCallback

type ResponseHandlerRecoveryCallback func(ResponseHandlerRecoveryInfo) error

ResponseHandlerRecoveryCallback defines the callback signature for response handler recovery This allows the main application to provide the actual implementation without creating import cycles

type ResponseHandlerRecoveryInfo

type ResponseHandlerRecoveryInfo struct {
	PhoneNumber   string
	ParticipantID string
	FlowType      models.FlowType
	HandlerType   string
	TTL           time.Duration
}

ResponseHandlerRecoveryInfo holds metadata about response handlers

type TimerRecoveryInfo

type TimerRecoveryInfo struct {
	ParticipantID string
	FlowType      models.FlowType
	StateType     models.StateType
	DataKey       models.DataKey
	OriginalTTL   time.Duration
	CreatedAt     time.Time
}

TimerRecoveryInfo holds metadata about a timer that needs to be recovered

Jump to

Keyboard shortcuts

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