domain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrQueueAlreadyExists is returned when the queue already exists.
	ErrQueueAlreadyExists = errors.New("queue already exists")
	// ErrQueueNotFound is returned when the queue is not found.
	ErrQueueNotFound = errors.New("queue not found")
	// ErrMessageAlreadyExists is returned when the message already exists.
	ErrMessageAlreadyExists = errors.New("message already exists")
	// ErrMessageNotFound is returned when the message is not found.
	ErrMessageNotFound = errors.New("message not found")
)

Functions

func NewLogger

func NewLogger(logLevel string) *slog.Logger

NewLogger returns a configured JSON logger.

Types

type Config

type Config struct {
	Testing                        bool
	LogLevel                       string
	ServerHost                     string
	ServerPort                     uint
	ServerReadHeaderTimeoutSeconds uint
	DatabaseURL                    string
	TestDatabaseURL                string
	DatabaseMinConns               uint
	DatabaseMaxConns               uint
	QueueMaxNumberOfMessages       uint
}

Config holds all application configuration data.

func NewConfig

func NewConfig() *Config

NewConfig returns a Config with values loaded from environment variables.

type Message

type Message struct {
	ID               string            `json:"id" db:"id"`
	QueueID          string            `json:"queue_id" db:"queue_id"`
	Label            *string           `json:"label" db:"label" form:"label"`
	Body             string            `json:"body" db:"body" form:"body"`
	Attributes       map[string]string `json:"attributes" db:"attributes" form:"attributes"`
	DeliveryAttempts uint              `json:"delivery_attempts" db:"delivery_attempts"`
	ExpiredAt        time.Time         `json:"-" db:"expired_at"`
	ScheduledAt      time.Time         `json:"-" db:"scheduled_at"`
	CreatedAt        time.Time         `json:"created_at" db:"created_at"`
	UpdatedAt        time.Time         `json:"-" db:"updated_at"`
}

Message entity.

func (*Message) Ack

func (m *Message) Ack(now time.Time)

func (*Message) DeliverySetup

func (m *Message) DeliverySetup(queue *Queue, now time.Time)

func (*Message) Enqueue

func (m *Message) Enqueue(queue *Queue, now time.Time)

func (*Message) Nack

func (m *Message) Nack(now time.Time, visibilityTimeoutSeconds uint)

func (Message) Validate

func (m Message) Validate() error

type MessageRepository

type MessageRepository interface {
	Create(ctx context.Context, message *Message) error
	Get(ctx context.Context, id string) (*Message, error)
	List(ctx context.Context, queue *Queue, label *string, limit uint) ([]*Message, error)
	Ack(ctx context.Context, id string) error
	Nack(ctx context.Context, id string, visibilityTimeoutSeconds uint) error
}

MessageRepository is the repository interface for the Message entity.

type MessageService

type MessageService interface {
	Create(ctx context.Context, message *Message) error
	List(ctx context.Context, queueID string, label *string, limit uint) ([]*Message, error)
	Ack(ctx context.Context, id string) error
	Nack(ctx context.Context, id string, visibilityTimeoutSeconds uint) error
}

MessageService is the service interface for the Message entity.

type Queue

type Queue struct {
	ID                      string    `json:"id" db:"id" form:"id"`
	AckDeadlineSeconds      uint      `json:"ack_deadline_seconds" db:"ack_deadline_seconds" form:"ack_deadline_seconds"`
	MessageRetentionSeconds uint      `json:"message_retention_seconds" db:"message_retention_seconds" form:"message_retention_seconds"`
	DeliveryDelaySeconds    uint      `json:"delivery_delay_seconds" db:"delivery_delay_seconds" form:"delivery_delay_seconds"`
	CreatedAt               time.Time `json:"created_at" db:"created_at"`
	UpdatedAt               time.Time `json:"updated_at" db:"updated_at"`
}

Queue entity.

func (Queue) Validate

func (q Queue) Validate() error

type QueueRepository

type QueueRepository interface {
	Create(ctx context.Context, queue *Queue) error
	Update(ctx context.Context, queue *Queue) error
	Get(ctx context.Context, id string) (*Queue, error)
	List(ctx context.Context, offset, limit int) ([]*Queue, error)
	Delete(ctx context.Context, id string) error
	Stats(ctx context.Context, id string) (*QueueStats, error)
	Purge(ctx context.Context, id string) error
	Cleanup(ctx context.Context, id string) error
}

QueueRepository is the repository interface for the Queue entity.

type QueueService

type QueueService interface {
	Create(ctx context.Context, queue *Queue) error
	Update(ctx context.Context, queue *Queue) error
	Get(ctx context.Context, id string) (*Queue, error)
	List(ctx context.Context, offset, limit int) ([]*Queue, error)
	Delete(ctx context.Context, id string) error
	Stats(ctx context.Context, id string) (*QueueStats, error)
	Purge(ctx context.Context, id string) error
	Cleanup(ctx context.Context, id string) error
}

QueueService is the service interface for the Queue entity.

type QueueStats

type QueueStats struct {
	NumUndeliveredMessages         int `json:"num_undelivered_messages"`
	OldestUnackedMessageAgeSeconds int `json:"oldest_unacked_message_age_seconds"`
}

QueueStats entity.

Jump to

Keyboard shortcuts

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