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 ¶
- type Record
- type RunInbox
- type SQLiteRunInbox
- func (i *SQLiteRunInbox) Close() error
- func (i *SQLiteRunInbox) DeleteTerminalBefore(ctx context.Context, topic string, before time.Time) (int64, error)
- func (i *SQLiteRunInbox) GetNonTerminal(ctx context.Context, topic string) ([]Record, error)
- func (i *SQLiteRunInbox) MarkCompleted(ctx context.Context, topic string, streamSeq uint64) error
- func (i *SQLiteRunInbox) MarkFailed(ctx context.Context, topic string, streamSeq uint64, errMsg string) error
- func (i *SQLiteRunInbox) MarkProcessing(ctx context.Context, topic string, streamSeq uint64) error
- func (i *SQLiteRunInbox) PutIfAbsent(ctx context.Context, topic string, streamSeq uint64, ...) (bool, *Record, error)
- type Status
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 ¶
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) 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 ¶
GetNonTerminal returns non-terminal records for a topic, ordered by stream_seq.
func (*SQLiteRunInbox) MarkCompleted ¶
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 ¶
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.