idempotence

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultTimeout       = 5 * time.Second // 5 seconds
	DefaultSuccessfulTTL = 24 * time.Hour  // 24 hours
	StatusProcessing     = "processing"
	StatusProcessed      = "processed"
)

Variables

View Source
var ErrConflict = errors.New("conflict")

Functions

func WithDeploymentID added in v0.13.0

func WithDeploymentID(deploymentID string) func(opts *IdempotenceImplOptions)

func WithSuccessfulTTL

func WithSuccessfulTTL(successfulTTL time.Duration) func(opts *IdempotenceImplOptions)

func WithTimeout

func WithTimeout(timeout time.Duration) func(opts *IdempotenceImplOptions)

Types

type Idempotence

type Idempotence interface {
	Exec(ctx context.Context, key string, exec func(context.Context) error) error
	// Processed reports whether key was marked processed (by MarkProcessed or
	// a successful Exec) within the SuccessfulTTL window.
	Processed(ctx context.Context, key string) (bool, error)
	// MarkProcessed marks key processed for the SuccessfulTTL window.
	MarkProcessed(ctx context.Context, key string) error
}

Idempotence deduplicates work by key. Exec is the packaged form: it claims the key, runs the callback, and marks the key processed — for work that completes within one call. Processed and MarkProcessed expose the check and mark phases separately, for callers whose work spans a boundary Exec can't wrap (e.g. the effects finish on another goroutine); such callers get no in-flight conflict detection — concurrent duplicates both run, so their effects must tolerate duplication.

func New

func New(redisClient redis.Cmdable, opts ...func(opts *IdempotenceImplOptions)) Idempotence

type IdempotenceImpl

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

func (*IdempotenceImpl) Exec

func (i *IdempotenceImpl) Exec(ctx context.Context, key string, exec func(context.Context) error) error

func (*IdempotenceImpl) MarkProcessed added in v1.1.0

func (i *IdempotenceImpl) MarkProcessed(ctx context.Context, key string) error

func (*IdempotenceImpl) Processed added in v1.1.0

func (i *IdempotenceImpl) Processed(ctx context.Context, key string) (bool, error)

type IdempotenceImplOptions

type IdempotenceImplOptions struct {
	Timeout       time.Duration
	SuccessfulTTL time.Duration
	DeploymentID  string
}

Jump to

Keyboard shortcuts

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