inbox

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package inbox provides a strongly-typed durable inbox for worker run commands.

The inbox stores complete WorkerCommand JSON keyed by topic + stream_seq, enabling at-least-once crash recovery. Non-terminal records are re-dispatched on worker restart.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Record

type Record struct {
	ID        uint64 `json:"id"`
	Topic     string `json:"topic"`
	StreamSeq uint64 `json:"stream_seq"`
	Command   string `json:"command"`
	Status    Status `json:"status"`
	ErrorMsg  string `json:"error_msg,omitempty"`
	CreatedAt int64  `json:"created_at"`
	UpdatedAt int64  `json:"updated_at"`
}

Record is a durable inbox entry.

func (*Record) IsTerminal

func (r *Record) IsTerminal() bool

IsTerminal returns true if the record has reached a terminal state.

type RunInbox

type RunInbox interface {
	// PutIfAbsent inserts a new record. Returns (true, nil) on insert,
	// (false, existing record, nil) if already exists, or an error.
	PutIfAbsent(ctx context.Context, topic string, streamSeq uint64, cmd messaging.WorkerCommand) (bool, *Record, error)

	// MarkProcessing transitions a record to processing.
	MarkProcessing(ctx context.Context, topic string, streamSeq uint64) error

	// MarkCompleted transitions a record to completed.
	MarkCompleted(ctx context.Context, topic string, streamSeq uint64) error

	// MarkFailed transitions a record to failed.
	MarkFailed(ctx context.Context, topic string, streamSeq uint64, errMsg string) error

	// GetNonTerminal returns non-terminal records for a topic, ordered by stream_seq.
	GetNonTerminal(ctx context.Context, topic string) ([]Record, error)

	// DeleteTerminalBefore deletes terminal records older than the given time.
	DeleteTerminalBefore(ctx context.Context, topic string, before time.Time) (int64, error)

	// Close closes the database.
	Close() error
}

RunInbox persists worker run commands for at-least-once crash recovery.

type SQLiteRunInbox

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

SQLiteRunInbox implements RunInbox using SQLite.

func NewSQLiteRunInbox

func NewSQLiteRunInbox(dbPath string) (*SQLiteRunInbox, error)

NewSQLiteRunInbox opens or creates the worker_run_inbox table.

func (*SQLiteRunInbox) Close

func (i *SQLiteRunInbox) Close() error

Close closes the database.

func (*SQLiteRunInbox) DeleteTerminalBefore

func (i *SQLiteRunInbox) DeleteTerminalBefore(ctx context.Context, topic string, before time.Time) (int64, error)

DeleteTerminalBefore deletes terminal records older than the given time.

func (*SQLiteRunInbox) GetNonTerminal

func (i *SQLiteRunInbox) GetNonTerminal(ctx context.Context, topic string) ([]Record, error)

GetNonTerminal returns non-terminal records for a topic, ordered by stream_seq.

func (*SQLiteRunInbox) MarkCompleted

func (i *SQLiteRunInbox) MarkCompleted(ctx context.Context, topic string, streamSeq uint64) error

MarkCompleted transitions a record to completed.

func (*SQLiteRunInbox) MarkFailed

func (i *SQLiteRunInbox) MarkFailed(ctx context.Context, topic string, streamSeq uint64, errMsg string) error

MarkFailed transitions a record to failed.

func (*SQLiteRunInbox) MarkProcessing

func (i *SQLiteRunInbox) MarkProcessing(ctx context.Context, topic string, streamSeq uint64) error

MarkProcessing transitions a record to processing.

func (*SQLiteRunInbox) PutIfAbsent

func (i *SQLiteRunInbox) PutIfAbsent(ctx context.Context, topic string, streamSeq uint64, cmd messaging.WorkerCommand) (bool, *Record, error)

PutIfAbsent inserts a new record with the command serialized to JSON.

type Status

type Status string

Status represents the processing state of an inbox record.

const (
	StatusPending    Status = "pending"
	StatusProcessing Status = "processing"
	StatusCompleted  Status = "completed"
	StatusFailed     Status = "failed"
)

Jump to

Keyboard shortcuts

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