pg

package
v0.2.16 Latest Latest
Warning

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

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

Documentation

Overview

Package pg is a Postgres-backed dispatch.Store for the hosted control plane. The OSS single-host controller uses the in-memory + JSONL *dispatch.Ledger; the hosted control plane points at Neon so dispatch state survives Fly machine restarts and the web app can read it. Same contract either way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store implements dispatch.Store against Postgres. Resolving deletes the row, so every row is a live dispatch and the partial unique index gives the same one-unstarted-dispatch-per-job dedup as the JSONL ledger.

func NewWithPool

func NewWithPool(ctx context.Context, pool *pgxpool.Pool) (*Store, error)

NewWithPool applies the schema on an existing pool and returns a Store sharing it (the caller owns the pool's lifetime — used to share one pool with enroll).

func Open

func Open(ctx context.Context, dsn string) (*Store, error)

Open connects to dsn, applies the schema, and returns the Store.

func (*Store) Claim

func (s *Store) Claim(id string, at time.Time, wantOrgs []string) (dispatch.Record, bool, error)

Claim transitions offered -> claimed. ok is false if the record is unknown, not offered (double claim), or owned by another tenant (org not in wantOrgs).

func (*Store) Close

func (s *Store) Close()

Close releases the connection pool.

func (*Store) ExpireOffer

func (s *Store) ExpireOffer(id string) bool

ExpireOffer deletes id only if it is still offered (see Store.ExpireOffer).

func (*Store) Offer

func (s *Store) Offer(r dispatch.Record) error

Offer inserts a new offered record. A duplicate id or (org, job_id) returns dispatch.ErrDuplicate so the server can distinguish it from an I/O error.

func (*Store) Resolve

func (s *Store) Resolve(id, _ string, wantOrgs []string) (dispatch.Record, bool, error)

Resolve removes a live record in any state. ok is false if it is unknown (already resolved) or owned by another tenant (org not in wantOrgs). status is not persisted — the row is deleted.

func (*Store) Snapshot

func (s *Store) Snapshot() []dispatch.Record

Snapshot returns every live record. On a query error it logs and returns nil (the interface has no error channel); the sweep simply finds nothing to do.

func (*Store) Start added in v0.2.13

func (s *Store) Start(id, agent string, wantOrgs []string) (dispatch.Record, bool, error)

Start transitions claimed -> started. ok is false if the record is unknown, not claimed, held by another agent, or owned by another tenant.

Jump to

Keyboard shortcuts

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