Help us shape the future of Go! Take the 2026 Go Developer Survey

openrails

package
v0.128.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package openrails reads OpenRails facts using an inbox-owned cursor. Hosts own identity mapping, optional-event policy and scheduling.

Index

Constants

This section is empty.

Variables

View Source
var ErrCursorExpired = errors.New("openrails notifications: event cursor expired; resync required")

ErrCursorExpired requires an explicit destination resync. Consume never silently starts over or skips a lost interval.

View Source
var ErrInboxHandoffRequired = errors.New("openrails notifications: finish the explicit inbox handoff before retiring polling jobs")

ErrInboxHandoffRequired means old source facts remain beyond the saved inbox cursor. Explicitly Consume those pages before retiring the old poller.

Functions

func BillingLifecycle added in v0.89.0

func BillingLifecycle(event Event) bool

BillingLifecycle selects unexpected billing outcomes. OpenRails keeps its complete event history; ContentKit avoids notifying about a user's own click.

Types

type Backend added in v0.89.0

type Backend interface {
	ListEvents(context.Context, string, int) (EventPage, error)
}

Backend reads a merchant-bound log without changing source state. Expired and reset cursors return ErrCursorExpired.

type ConsumeOptions

type ConsumeOptions struct {
	Limit           int
	IncludeOptional bool
	Filter          func(Event) bool
}

type ConsumeResult

type ConsumeResult struct {
	Fetched, Delivered, Skipped int
	HasMore                     bool
}

type Event

type Event struct {
	ID         string          `json:"id"`
	MerchantID string          `json:"merchant_id"`
	Source     string          `json:"source"`
	EventType  string          `json:"type"`
	Version    int             `json:"version"`
	Subject    EventSubject    `json:"subject"`
	Data       json.RawMessage `json:"data"`
	CreatedAt  time.Time       `json:"occurred_at"`
	CustomerID string          `json:"-"`
	// Nil means unknown historical ownership, not a native account.
	AccountIssuer   *string `json:"-"`
	ActionRequested bool    `json:"-"`
	Optional        bool    `json:"-"`
}

Event is the retained source snapshot. Customer fields are derived from its data, never fetched from a billing row which may have since been deleted.

type EventPage added in v0.116.0

type EventPage struct {
	Events           []Event `json:"events"`
	NextCursor       string  `json:"next_cursor"`
	HasMore          bool    `json:"has_more"`
	RetentionSeconds int64   `json:"retention_seconds"`
}

type EventSubject added in v0.116.0

type EventSubject struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

type Inbox added in v0.116.0

Inbox owns both publication and progress. Implementations must commit the effects and cursor atomically; the producer stores no consumer state.

type Options

type Options struct {
	Backend    Backend
	Name       string
	URL        string
	MerchantID string
	Client     *http.Client
	Token      func(context.Context) (string, error)
}

Options binds one trusted deployment and merchant. Token supplies a merchant-authorized application token; Client can authenticate instead. URL precedes /v1. A native Backend needs no URL or network credentials.

type RecipientMapper

type RecipientMapper func(context.Context, Event) (recipientID string, deliver bool, err error)

RecipientMapper resolves verified source coordinates to a local account. False deliberately skips a fact; errors leave the whole page for retry. Email equality alone must never establish the association.

type Source

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

func New

func New(opts Options) (*Source, error)

New validates the trusted source. HTTP requests have a fifteen-second deadline and refuse redirects to keep credentials on that deployment.

func (*Source) Consume

func (s *Source) Consume(ctx context.Context, destination Inbox, mapper RecipientMapper, opts ConsumeOptions) (ConsumeResult, error)

Consume reads one page and atomically commits its notices and continuation. A failed mapping or write commits neither. Other source facts are skipped but advance the cursor, so a busy host-event log cannot stall the inbox.

func (*Source) Origin added in v0.89.0

func (s *Source) Origin() notify.OriginScope

func (*Source) RetireInboxSync added in v0.127.0

func (s *Source) RetireInboxSync(ctx context.Context, pool *pgxpool.Pool, riverSchema, namespace string, destination Inbox) error

RetireInboxSync cancels only this source's unfinished legacy polling jobs. Call during an explicit stopped-writer migration after the final Consume pass and before enabling direct producer publication. It is not a runtime worker. Terminal history, other sources, general events and inbox receipts survive.

Jump to

Keyboard shortcuts

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