idempotency

package
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryInitTable = "InitTable"
	QueryClaim     = "Claim"
	QueryMarkSent  = "MarkSent"
	QueryRelease   = "Release"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SQLiteStore

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

SQLiteStore is a minimal idempotency store backed by SQLite.

func NewSQLiteStore

func NewSQLiteStore(dsn string) (*SQLiteStore, error)

NewSQLiteStore opens (or creates) a SQLite database at dsn and ensures the idempotency table exists. dsn can be a file path like "hermod.db" or a full SQLite DSN.

func NewSQLiteStoreWithTable

func NewSQLiteStoreWithTable(dsn, table string) (*SQLiteStore, error)

NewSQLiteStoreWithTable allows specifying a custom table name (namespace).

func (*SQLiteStore) Claim

func (s *SQLiteStore) Claim(ctx context.Context, key string) (bool, error)

Claim attempts to insert the key; returns true if inserted (we own it), false if it already exists.

func (*SQLiteStore) CleanupTTL

func (s *SQLiteStore) CleanupTTL(ctx context.Context, ttl time.Duration) error

CleanupTTL removes entries with last_update older than now-ttl. This is a best-effort maintenance function; errors are returned but safe to ignore by callers.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close closes the underlying DB.

func (*SQLiteStore) MarkSent

func (s *SQLiteStore) MarkSent(ctx context.Context, key string) error

MarkSent marks the key as successfully processed.

func (*SQLiteStore) Release

func (s *SQLiteStore) Release(ctx context.Context, key string) error

Release gives up a claim that never completed, so a retry can take it again.

A claim is taken before the work and marked sent afterwards. Without a way to give it up, a failed attempt leaves the key claimed for good: the retry is told it was already handled, and the message is dropped while the caller reports a suppressed duplicate. That is at-most-once wearing at-least-once's clothes, and it is the delivery guarantee this package underwrites.

Only unsent claims are released. A key that was marked sent stays, because releasing it would re-admit the duplicate the whole store exists to suppress.

Releasing something never claimed is not an error: retry paths call this speculatively, and failing them over a no-op would be its own bug.

Jump to

Keyboard shortcuts

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