postgres

package
v0.0.0-...-f03e6b7 Latest Latest
Warning

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

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

Documentation

Overview

Package postgres persists event rules, durable events, and executions in PostgreSQL.

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 is the PostgreSQL event-rule persistence boundary shared by the processor, scheduler, and executors.

func New

func New(pg *cdb.Session) *Store

New constructs a PostgreSQL-backed event-rule store.

func (*Store) Bind

func (s *Store) Bind(ctx context.Context, binding eventrule.Binding) error

Bind stores a rule-to-scope association. Locking the parent rule serializes the site-versus-rack check for concurrent bindings of the same rule; partial unique indexes serialize conflicts for the same resolved scope.

func (*Store) ClaimPendingExecutions

func (s *Store) ClaimPendingExecutions(
	ctx context.Context,
	request eventrule.ExecutionClaimRequest,
) (eventrule.ExecutionClaimBatch, error)

ClaimPendingExecutions atomically allocates pending attempts.

func (*Store) ClaimRetryExecutions

func (s *Store) ClaimRetryExecutions(
	ctx context.Context,
	request eventrule.ExecutionClaimRequest,
) (eventrule.ExecutionClaimBatch, error)

ClaimRetryExecutions atomically allocates due deferred or expired attempts.

func (*Store) CommitEventPlan

func (s *Store) CommitEventPlan(
	ctx context.Context,
	definition eventrule.Event,
	planned []eventrule.PlannedExecution,
) (*eventrule.Event, error)

CommitEventPlan atomically inserts an event and all immutable action plans. A duplicate source event records another observation without changing or resuming its existing executions.

func (*Store) Create

func (s *Store) Create(
	ctx context.Context,
	rule *eventrule.Rule,
) (*eventrule.Rule, error)

Create stores a new persisted rule using database-owned timestamps.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id uuid.UUID) error

Delete atomically deletes a persisted rule and its cascading bindings.

func (*Store) Events

func (s *Store) Events(ctx context.Context) ([]eventrule.Event, error)

Events returns stable event snapshots for diagnostics and integration tests without recording another observation.

func (*Store) Executions

func (s *Store) Executions(ctx context.Context) ([]eventrule.Execution, error)

Executions returns stable execution snapshots for diagnostics and integration tests.

func (*Store) GetByID

func (s *Store) GetByID(
	ctx context.Context,
	id uuid.UUID,
) (*eventrule.Rule, error)

GetByID returns one persisted rule.

func (*Store) GetForScope

func (s *Store) GetForScope(
	ctx context.Context,
	eventType eventrule.Type,
	scope eventrule.Scope,
) (*eventrule.Binding, error)

GetForScope returns the binding for an event type and scope.

func (*Store) List

List returns persisted rules matching the filter in stable ID order.

func (*Store) ObserveEvent

func (s *Store) ObserveEvent(
	ctx context.Context,
	key eventrule.EventKey,
) (*eventrule.Event, error)

ObserveEvent records and returns an existing source event. Missing events are represented by (nil, nil).

func (*Store) ReplaceActions

func (s *Store) ReplaceActions(
	ctx context.Context,
	id uuid.UUID,
	actions []eventrule.Action,
) error

ReplaceActions replaces all actions belonging to one persisted rule.

func (*Store) SetEnabled

func (s *Store) SetEnabled(
	ctx context.Context,
	id uuid.UUID,
	enabled bool,
) error

SetEnabled changes one persisted rule's enabled state.

func (*Store) TransitionClaimedExecution

func (s *Store) TransitionClaimedExecution(
	ctx context.Context,
	id uuid.UUID,
	token uuid.UUID,
	result eventrule.ExecutionResult,
) error

TransitionClaimedExecution persists an attempt result only while token owns the locked running execution. Expiration alone does not invalidate the token.

func (*Store) Unbind

func (s *Store) Unbind(
	ctx context.Context,
	eventType eventrule.Type,
	scope eventrule.Scope,
) error

Unbind atomically deletes the binding for an event type and scope.

func (*Store) UpdateMetadata

func (s *Store) UpdateMetadata(
	ctx context.Context,
	id uuid.UUID,
	metadata eventrule.RuleMetadata,
) error

UpdateMetadata updates one persisted rule's descriptive fields.

Jump to

Keyboard shortcuts

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