dbeventbus

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRetriable

func IsRetriable(err error) bool

IsRetriable checks if an error is retriable

func NewRetriableError

func NewRetriableError(err error) error

NewRetriableError creates a new retriable error

Types

type Event

type Event struct {
	ID        int64     `db:"id"`
	Name      string    `db:"name"`
	Payload   string    `db:"payload"`
	CreatedAt time.Time `db:"created_at"`
}

type EventBus

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

func NewEventBus

func NewEventBus(db *sqlx.DB, log *slog.Logger) (*EventBus, error)

func (*EventBus) Publish

func (b *EventBus) Publish(ctx context.Context, tx sqlx.ExecerContext, topic string, payload interface{}) error

func (*EventBus) Subscribe

func (b *EventBus) Subscribe(ctx context.Context, topic, queueName string, handler Handler, opts Options) error

type EventProcessing

type EventProcessing struct {
	EventID     int64     `db:"event_id"`
	Subscriber  string    `db:"subscriber"`
	Status      string    `db:"status"`
	RetryCount  int       `db:"retry_count"`
	CreatedAt   time.Time `db:"created_at"`
	Heartbeat   time.Time `db:"heartbeat"`
	LastAttempt time.Time `db:"last_attempt"`

	ErrorMessage *string    `db:"error_message"`
	FinishedAt   *time.Time `db:"finished_at"`
	NextAttempt  *time.Time `db:"next_attempt"`
}

type Handler

type Handler func(ctx context.Context, payload []byte) error

type Options

type Options struct {
	Concurrency       int
	MaxRetries        int
	Backoff           func(retry int) time.Duration
	PollInterval      time.Duration
	HeartbeatInterval time.Duration
}

type RetriableError

type RetriableError struct {
	Err error
}

RetriableError wraps an error that should be retried

func (*RetriableError) Error

func (e *RetriableError) Error() string

func (*RetriableError) Unwrap

func (e *RetriableError) Unwrap() error

Jump to

Keyboard shortcuts

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