Documentation
¶
Overview ¶
Package postgres keeps the runs of grpcproc/saga in PostgreSQL: Store is a saga.Store, in one table, a row per run, its inbox on the row.
db, err := sql.Open("pgx", dsn) // any driver for PostgreSQL
store, err := postgres.NewStore(db, "grpcproc_sagas")
err = store.Migrate(ctx) // or apply store.Schema() with your migrations
eng, err := saga.Start(node, saga.Config{Store: store}, orders)
It takes a *sql.DB the application opens, with the driver, credentials and pool it chooses. Every change to a run is one statement on its row, so a run's state and its signals change together. A statement that changes a run waits for one that holds its row, and works on what that one wrote; Claim skips such a run instead. Create, Claim and Save return the row as they left it.
Leases and due times are read on the database's clock, which every engine shares; the times an engine sets, a run's Wake among them, are its own. A timer of an engine whose clock is set apart from the database's fires that much early or late; a lease is safe all the same, since an engine counts its own lease from before it asked for it.
Index ¶
- type Store
- func (s *Store) Claim(ctx context.Context, owner string, sagas map[string]uint64, ttl time.Duration, ...) ([]saga.Record, error)
- func (s *Store) Create(ctx context.Context, r saga.Record) (saga.Record, bool, error)
- func (s *Store) Get(ctx context.Context, sagaName, id string) (saga.Record, bool, error)
- func (s *Store) List(ctx context.Context, sagaName string) ([]saga.Record, error)
- func (s *Store) Migrate(ctx context.Context) error
- func (s *Store) Renew(ctx context.Context, sagaName, id string, epoch uint64, ttl time.Duration) error
- func (s *Store) Resume(ctx context.Context, sagaName, id string) error
- func (s *Store) Save(ctx context.Context, r saga.Record) (saga.Record, error)
- func (s *Store) Schema() string
- func (s *Store) Signal(ctx context.Context, sagaName, id string, sig saga.Signal) error
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 is a saga.Store in PostgreSQL. Engines on several nodes, and programs that share the database, share the runs.
func NewStore ¶
NewStore returns the store kept in the table name of db. It does not touch the database: Migrate, or the application's own migrations applying Schema, creates the table.
func (*Store) Claim ¶
func (s *Store) Claim(ctx context.Context, owner string, sagas map[string]uint64, ttl time.Duration, n int) ([]saga.Record, error)
Claim gives owner up to n runs that are due.
func (*Store) Create ¶
Create adds r, unless its saga has a run with its ID: then it returns that run, and false.
func (*Store) Migrate ¶
Migrate brings the store's tables to what this version of the package wants: it makes them, or takes them on from where an earlier version left them, by the version kept beside them. Programs that start at once may each call it: they take turns.
func (*Store) Renew ¶
func (s *Store) Renew(ctx context.Context, sagaName, id string, epoch uint64, ttl time.Duration) error
Renew extends the lease of a run to ttl from now.