delivery

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxAttempts = 3
	DefaultBackoff     = 30 * time.Second
)

Variables

View Source
var ErrWorkspaceRequired = workspace.ErrRequired

Functions

func FailureDisableReason

func FailureDisableReason(result Result) string

func Payload

func Payload(event eventcontract.Event, now time.Time) (string, error)

func RetryableStatus

func RetryableStatus(statusCode int) bool

Types

type Attempt

type Attempt struct {
	EndpointID  string
	WorkspaceID string
	EventType   eventcontract.Type
	Attempt     int
	Status      Status
	StatusCode  int
	ErrorClass  ErrorClass
	Error       string
	Retry       bool
	NextRetryAt *time.Time
	Evidence    Evidence
	RecordedAt  time.Time
}

type Clock

type Clock interface {
	Now() time.Time
}

type Endpoint

type Endpoint struct {
	ID             string
	WorkspaceID    string
	URL            string
	Disabled       bool
	DisabledReason string
}

type ErrorClass

type ErrorClass string
const (
	ErrorNone       ErrorClass = ""
	ErrorHTTPStatus ErrorClass = "http_status"
	ErrorNetwork    ErrorClass = "network"
	ErrorSigning    ErrorClass = "signing"
	ErrorStore      ErrorClass = "store"
	ErrorDisabled   ErrorClass = "endpoint_disabled"
)

type Evidence

type Evidence struct {
	EndpointID  string
	EndpointURL string
	WorkspaceID string
	EventType   eventcontract.Type
	Status      Status
	StatusCode  int
	ErrorClass  ErrorClass
	Attempt     int
	NextRetryAt *time.Time
}

type HTTPClient

type HTTPClient interface {
	PostWebhook(ctx context.Context, req HTTPRequest) (HTTPResponse, error)
}

type HTTPRequest

type HTTPRequest struct {
	URL     string
	Body    string
	Headers map[string]string
}

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
}

type Request

type Request struct {
	WorkspaceID string
	Event       eventcontract.Event
	Attempt     int
}

type Result

type Result struct {
	EndpointID  string
	WorkspaceID string
	EventType   eventcontract.Type
	Attempt     int
	Status      Status
	StatusCode  int
	ErrorClass  ErrorClass
	Error       string
	Retry       bool
	NextRetryAt *time.Time
	Evidence    Evidence
}

type Status

type Status string
const (
	Delivered        Status = "delivered"
	Retryable        Status = "retryable"
	Failed           Status = "failed"
	EndpointDisabled Status = "endpoint_disabled"
	Skipped          Status = "skipped"
)

type Store

type Store interface {
	ListWebhookDeliveryEndpoints(ctx context.Context, workspaceID string) ([]Endpoint, error)
	RecordWebhookDelivery(ctx context.Context, attempt Attempt) error
	DisableWebhookDeliveryEndpoint(ctx context.Context, endpoint Endpoint, reason string, now time.Time) error
}

type Worker

type Worker struct {
	Store       Store
	Client      HTTPClient
	Clock       Clock
	Secret      string
	MaxAttempts int
	Backoff     func(attempt int) time.Duration
}

func (Worker) Deliver

func (w Worker) Deliver(ctx context.Context, req Request) ([]Result, error)

Jump to

Keyboard shortcuts

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