guardedeffects

package
v0.140.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusPrepared     = "prepared"
	StatusDispatching  = "dispatching"
	StatusGuardPending = "guard_pending"
	StatusFinalized    = "finalized"
	StatusRetrying     = "retrying"
	StatusAborted      = "aborted"
	StatusDeadLettered = "dead_lettered"

	OutcomeCompleted = "completed"
	OutcomePending   = "pending"
	OutcomeFailed    = "failed"

	PolicySMTPAccepted = "smtp_accepted"
)

Variables

This section is empty.

Functions

func NormalizeOutcome

func NormalizeOutcome(raw string) string

func NormalizeStatus

func NormalizeStatus(raw string) string

Types

type AbortHandler

type AbortHandler interface {
	Abort(ctx context.Context, effect Record, reason string) error
}

AbortHandler receives explicit effect-abort lifecycle events.

type CompletionPolicy

type CompletionPolicy interface {
	Name() string
	EvaluateDispatchResult(result DispatchResult) Evaluation
}

CompletionPolicy classifies one dispatch result.

type DispatchResult

type DispatchResult struct {
	Outcome           string    `json:"outcome"`
	DispatchID        string    `json:"dispatch_id"`
	ProviderMessageID string    `json:"provider_message_id"`
	MetadataJSON      string    `json:"metadata_json"`
	OccurredAt        time.Time `json:"occurred_at"`
}

DispatchResult is the structured external-effect completion signal consumed by effect finalizers.

type Evaluation

type Evaluation struct {
	Outcome string `json:"outcome"`
	Reason  string `json:"reason"`
}

Evaluation captures completion-policy output.

type Handler

type Handler interface {
	Finalize(ctx context.Context, effect Record, result DispatchResult) error
	Fail(ctx context.Context, effect Record, result DispatchResult, nextRetryAt *time.Time) error
}

Handler owns workflow-specific finalization and failure behavior.

type PendingHandler

type PendingHandler interface {
	Pending(ctx context.Context, effect Record, result DispatchResult) error
}

PendingHandler receives provider-accepted, not-yet-final outcomes.

type Record

type Record struct {
	EffectID            string     `json:"effect_id"`
	TenantID            string     `json:"tenant_id"`
	OrgID               string     `json:"org_id"`
	Kind                string     `json:"kind"`
	GroupType           string     `json:"group_type"`
	GroupID             string     `json:"group_id"`
	SubjectType         string     `json:"subject_type"`
	SubjectID           string     `json:"subject_id"`
	IdempotencyKey      string     `json:"idempotency_key"`
	CorrelationID       string     `json:"correlation_id"`
	Status              string     `json:"status"`
	AttemptCount        int        `json:"attempt_count"`
	MaxAttempts         int        `json:"max_attempts"`
	GuardPolicy         string     `json:"guard_policy"`
	PreparePayloadJSON  string     `json:"prepare_payload_json"`
	DispatchPayloadJSON string     `json:"dispatch_payload_json"`
	ResultPayloadJSON   string     `json:"result_payload_json"`
	ErrorJSON           string     `json:"error_json"`
	DispatchID          string     `json:"dispatch_id"`
	CreatedAt           time.Time  `json:"created_at"`
	UpdatedAt           time.Time  `json:"updated_at"`
	DispatchedAt        *time.Time `json:"dispatched_at"`
	FinalizedAt         *time.Time `json:"finalized_at"`
	AbortedAt           *time.Time `json:"aborted_at"`
	RetryAt             *time.Time `json:"retry_at"`
}

Record is the durable lifecycle boundary for a guarded external effect.

type SMTPAcceptedPolicy

type SMTPAcceptedPolicy struct{}

SMTPAcceptedPolicy treats provider acceptance as the completion boundary.

func (SMTPAcceptedPolicy) EvaluateDispatchResult

func (SMTPAcceptedPolicy) EvaluateDispatchResult(result DispatchResult) Evaluation

func (SMTPAcceptedPolicy) Name

func (SMTPAcceptedPolicy) Name() string

type Scope

type Scope struct {
	TenantID string `json:"tenant_id"`
	OrgID    string `json:"org_id"`
}

Scope identifies the tenant/org boundary used for idempotency and persistence.

type Service

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

Service coordinates durable status changes around guarded external effects.

func NewService

func NewService(store Store, now func() time.Time) Service

NewService builds a guarded effect lifecycle coordinator.

func (Service) Abort

func (s Service) Abort(
	ctx context.Context,
	scope Scope,
	effectID string,
	reason string,
	handler Handler,
) (Record, error)

Abort moves an effect into an explicit aborted terminal state.

func (Service) Complete

func (s Service) Complete(
	ctx context.Context,
	scope Scope,
	effectID string,
	policy CompletionPolicy,
	result DispatchResult,
	nextRetryAt *time.Time,
	handler Handler,
) (Record, error)

Complete applies one dispatch result and delegates workflow-specific finalize/failure handling.

func (Service) MarkDispatching

func (s Service) MarkDispatching(
	ctx context.Context,
	scope Scope,
	effectID string,
	dispatchID string,
) (Record, error)

MarkDispatching records the start of a real provider dispatch attempt.

func (Service) Prepare

func (s Service) Prepare(ctx context.Context, scope Scope, record Record) (Record, bool, error)

Prepare creates or replays a durable effect row by idempotency key.

type Store

type Store interface {
	SaveGuardedEffect(ctx context.Context, scope Scope, record Record) (Record, error)
	GetGuardedEffect(ctx context.Context, effectID string) (Record, error)
	GetGuardedEffectByIdempotencyKey(ctx context.Context, scope Scope, key string) (Record, error)
}

Store is the durable persistence boundary required by the guarded effect service.

Jump to

Keyboard shortcuts

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