Documentation
¶
Index ¶
- Constants
- type SQLiteStore
- func (s *SQLiteStore) Claim(ctx context.Context, key string) (bool, error)
- func (s *SQLiteStore) CleanupTTL(ctx context.Context, ttl time.Duration) error
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) MarkSent(ctx context.Context, key string) error
- func (s *SQLiteStore) Release(ctx context.Context, key string) error
Constants ¶
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 ¶
Claim attempts to insert the key; returns true if inserted (we own it), false if it already exists.
func (*SQLiteStore) CleanupTTL ¶
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) 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.