memory

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package memory is an in-memory metadata.Repository used as a test double. It mirrors the pgx implementation's observable semantics — live-only reads, soft delete, tag containment, keyset paging by id, reserved-key preservation on replace — so the layers above can be exercised without Postgres. It is not a deployment target.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

type Repo struct {

	// FailCreate makes every Create and CreateForKey fail, to exercise the
	// orphan-cleanup paths above this seam.
	FailCreate bool
	// contains filtered or unexported fields
}

Repo is a concurrency-safe in-memory repository. Every method honours context cancellation the way pgx does, so a caller that must run after its request context is gone can be tested for it.

func New

func New() *Repo

New returns an empty repository.

func (*Repo) ClaimIdempotencyKey

func (r *Repo) ClaimIdempotencyKey(ctx context.Context, key string) (bool, *metadata.IdempotencyRecord, error)

func (*Repo) ClaimJob

func (r *Repo) ClaimJob(ctx context.Context) (*metadata.Job, error)

func (*Repo) CountPendingJobs

func (r *Repo) CountPendingJobs(context.Context) (int, error)

func (*Repo) Create

func (r *Repo) Create(ctx context.Context, f *metadata.File) error

func (*Repo) CreateForKey

func (r *Repo) CreateForKey(ctx context.Context, f *metadata.File, key string) error

func (*Repo) CreateJob

func (r *Repo) CreateJob(ctx context.Context, j *metadata.Job) (bool, string, error)

func (*Repo) Delete

func (r *Repo) Delete(ctx context.Context, id string) error

func (*Repo) FinishJob

func (r *Repo) FinishJob(ctx context.Context, id string, attempt int, res metadata.JobResult) error

func (*Repo) Get

func (r *Repo) Get(ctx context.Context, id string) (*metadata.File, error)

func (*Repo) GetJob

func (r *Repo) GetJob(ctx context.Context, id string) (*metadata.Job, error)

func (*Repo) HeartbeatJob

func (r *Repo) HeartbeatJob(ctx context.Context, id string, attempt, done, total int) (bool, error)

func (*Repo) List

func (r *Repo) List(ctx context.Context, filter metadata.ListFilter) ([]*metadata.File, error)

List mirrors the pgx query: live rows unless IncludeDeleted, content-type equality, JSONB-style tag containment, the entries scope, and keyset paging by id descending — UUIDv7 ids sort by creation time, as in Postgres.

func (*Repo) ListDeleted

func (r *Repo) ListDeleted(_ context.Context, limit int) ([]*metadata.File, error)

func (*Repo) ParkJob

func (r *Repo) ParkJob(ctx context.Context, id string, attempt, done, total int) error

func (*Repo) Purge

func (r *Repo) Purge(_ context.Context, id string) error

func (*Repo) PurgeFinishedJobs

func (r *Repo) PurgeFinishedJobs(_ context.Context, before time.Time) (int, error)

func (*Repo) PurgeIdempotencyKeys

func (r *Repo) PurgeIdempotencyKeys(_ context.Context, before time.Time) (int, error)

func (*Repo) ReapJobs

func (r *Repo) ReapJobs(_ context.Context, ttl time.Duration) (int, error)

func (*Repo) ReleaseIdempotencyKey

func (r *Repo) ReleaseIdempotencyKey(ctx context.Context, key string) error

func (*Repo) RequestCancel

func (r *Repo) RequestCancel(ctx context.Context, id string) (*metadata.Job, error)

func (*Repo) StorageKeys

func (r *Repo) StorageKeys(context.Context) (map[string]struct{}, error)

func (*Repo) UpdateMetadata

func (r *Repo) UpdateMetadata(ctx context.Context, id string, tags map[string]any, merge bool) (*metadata.File, error)

Jump to

Keyboard shortcuts

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