pgstore

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package pgstore implements the job store ports on Postgres with pgx.

Index

Constants

View Source
const (
	OpCancel  = "cancel"
	OpDiscard = "discard"
	OpRetry   = "retry"
)
View Source
const CopyThreshold = 10
View Source
const DefaultSchema = "public"

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	CopyFrom(ctx context.Context, table pgx.Identifier, cols []string, src pgx.CopyFromSource) (int64, error)
	Begin(ctx context.Context) (pgx.Tx, error)
}

type Filter

type Filter struct {
	IDs           []int64
	Kinds         []string
	Queues        []string
	States        []job.State
	CreatedAfter  time.Time
	CreatedBefore time.Time
	BeforeID      int64
}

type Leader

type Leader struct {
	Name      string
	LeaderID  string
	ElectedAt time.Time
	ExpiresAt time.Time
}

type Listener

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

Listener holds a dedicated connection for LISTEN.

func (*Listener) Close

func (l *Listener) Close(ctx context.Context) error

func (*Listener) Connect

func (l *Listener) Connect(ctx context.Context) error

func (*Listener) Listen

func (l *Listener) Listen(ctx context.Context, channel string) error

func (*Listener) Ping

func (l *Listener) Ping(ctx context.Context) error

func (*Listener) WaitForNotification

func (l *Listener) WaitForNotification(ctx context.Context) (job.Notification, error)

type Names

type Names struct {
	Schema         string
	Quoted         string
	InsertChannel  string
	ControlChannel string
	LeaderChannel  string
	LockPrefix     string
}

func NewNames

func NewNames(schema string) (Names, error)

type PeriodicRow

type PeriodicRow struct {
	Name     string
	LastTick time.Time
	Ticks    int64
}

type QueueRow

type QueueRow struct {
	Name      string
	PausedAt  *time.Time
	UpdatedAt *time.Time
	Counts    map[job.State]int64
}

type Store

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

Store implements the job store ports on Postgres.

func New

func New(pool *pgxpool.Pool, schema string) (*Store, error)

New returns a Store for schema.

func (*Store) AcquireLease

func (s *Store) AcquireLease(ctx context.Context, name, id string, now time.Time, ttl time.Duration) (bool, error)

func (*Store) CancelRequested

func (s *Store) CancelRequested(ctx context.Context, ids []int64) ([]int64, error)

func (*Store) Complete

func (s *Store) Complete(ctx context.Context, clientID string, cs []job.Completion) ([]int64, error)

Complete writes the results of finished attempts.

func (*Store) CompleteTx

func (s *Store) CompleteTx(ctx context.Context, tx pgx.Tx, clientID string, ref job.Ref, now time.Time) error

func (*Store) DeleteFinalized

func (s *Store) DeleteFinalized(ctx context.Context, state job.State, cutoff time.Time, limit int) (int, error)

func (*Store) EnqueueTick

func (s *Store) EnqueueTick(ctx context.Context, name string, tick time.Time, p job.InsertParams) (bool, error)

func (*Store) Fetch

func (s *Store) Fetch(ctx context.Context, p job.FetchParams) ([]*job.Row, error)

Fetch takes the next jobs of a queue and marks them running.

func (*Store) FetchByID

func (s *Store) FetchByID(ctx context.Context, id int64, clientID string, now time.Time) (*job.Row, error)

func (*Store) Heartbeat

func (s *Store) Heartbeat(ctx context.Context, clientID string, now time.Time, refs []job.Ref) (int, error)

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, db DB, ps []job.InsertParams) ([]job.InsertResult, error)

Insert inserts jobs and returns one result per input.

func (*Store) JobDeleteAll

func (s *Store) JobDeleteAll(ctx context.Context, f Filter) (int, error)

func (*Store) JobGet

func (s *Store) JobGet(ctx context.Context, id int64) (*job.Row, error)

func (*Store) JobList

func (s *Store) JobList(ctx context.Context, f Filter, limit int) ([]*job.Row, error)

func (*Store) JobUpdate

func (s *Store) JobUpdate(ctx context.Context, op string, f Filter, now time.Time, limit int) ([]*job.Row, error)

func (*Store) JobUpdateAll

func (s *Store) JobUpdateAll(ctx context.Context, op string, f Filter, now time.Time) (int, error)

func (*Store) KeyStats

func (s *Store) KeyStats(ctx context.Context, queue string, limit int, withRunning bool) ([]job.KeyStat, error)

func (*Store) LastTicks

func (s *Store) LastTicks(ctx context.Context) (map[string]time.Time, error)

func (*Store) LeaderGet

func (s *Store) LeaderGet(ctx context.Context, name string) (*Leader, error)

func (*Store) MarkPeriodicStart

func (s *Store) MarkPeriodicStart(ctx context.Context, name string, now time.Time) error

func (*Store) Names

func (s *Store) Names() Names

func (*Store) NewListener

func (s *Store) NewListener() *Listener

NewListener returns a listener on the pool.

func (*Store) PeriodicList

func (s *Store) PeriodicList(ctx context.Context) ([]*PeriodicRow, error)

func (*Store) Pool

func (s *Store) Pool() *pgxpool.Pool

func (*Store) PromoteDue

func (s *Store) PromoteDue(ctx context.Context, now time.Time, limit int) (int, error)

func (*Store) PruneTicks

func (s *Store) PruneTicks(ctx context.Context, cutoff time.Time) (int, error)

func (*Store) QueueDepths

func (s *Store) QueueDepths(ctx context.Context) ([]job.QueueDepth, error)

func (*Store) QueueHeartbeat

func (s *Store) QueueHeartbeat(ctx context.Context, queue string, now time.Time) (bool, error)

func (*Store) QueueList

func (s *Store) QueueList(ctx context.Context) ([]*QueueRow, error)

func (*Store) QueueSetPaused

func (s *Store) QueueSetPaused(ctx context.Context, name string, paused bool, now time.Time) error

func (*Store) Reindex

func (s *Store) Reindex(ctx context.Context) (bool, error)

func (*Store) ReleaseLease

func (s *Store) ReleaseLease(ctx context.Context, name, id string) error

func (*Store) RenewLease

func (s *Store) RenewLease(ctx context.Context, name, id string, now time.Time, ttl time.Duration) (bool, error)

func (*Store) Rescue

func (s *Store) Rescue(ctx context.Context, cutoff time.Time, cs []job.Completion) (int, error)

func (*Store) ServedQueues

func (s *Store) ServedQueues(ctx context.Context, cutoff time.Time) ([]string, error)

func (*Store) StuckJobs

func (s *Store) StuckJobs(ctx context.Context, cutoff time.Time, limit int) ([]*job.Row, error)

Jump to

Keyboard shortcuts

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