webhook

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("webhook record not found")
	ErrAlreadyExists = errors.New("webhook record already exists")
)

Functions

This section is empty.

Types

type Record

type Record struct {
	Id uint64

	WebhookId string
	Url       string
	Type      Type

	Attempts uint8
	State    State

	CreatedAt     time.Time
	NextAttemptAt *time.Time
}

func (*Record) Clone

func (r *Record) Clone() Record

func (*Record) CopyTo

func (r *Record) CopyTo(dst *Record)

func (*Record) Validate

func (r *Record) Validate() error

type State

type State uint8
const (
	StateUnknown   State = iota // Not actionable (ie. the event to trigger hasn't occurred yet)
	StatePending                // Actively sending to third party
	StateConfirmed              // Third party successfully processed webhook
	StateFailed                 // Third party failed to process webhook after sufficient retries
)

func (State) String

func (s State) String() string

type Store

type Store interface {
	// Put creates a webhook record
	//
	// Returns ErrAlreadyExists if a record already exists.
	Put(ctx context.Context, record *Record) error

	// Update updates a webhook record
	//
	// Returns ErrNotFound if no record exists.
	Update(ctx context.Context, record *Record) error

	// Get finds the webhook record for a given webhook ID
	//
	// Returns ErrNotFound if no record is found.
	Get(ctx context.Context, webhookId string) (*Record, error)

	// CountByState counts all webhook records in a provided state
	CountByState(ctx context.Context, state State) (uint64, error)

	// GetAllPendingReadyToSend gets all webhook records in the pending state
	// that have an attempt scheduled to be sent.
	//
	// Returns ErrNotFound if no record is found.
	//
	// Note: No traditional pagination since it's expected the next attempt
	//       timestamp is updated or the state transitions to a terminal value.
	GetAllPendingReadyToSend(ctx context.Context, limit uint64) ([]*Record, error)
}

type Type

type Type uint8
const (
	TypeUnknown Type = iota
	TypeIntentSubmitted
	TypeTest
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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