queue

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package queue wires River with the sync engine's three priority-class queues (SYNC_ENGINE C-B3): interactive > event > sweep.

Index

Constants

View Source
const (
	// QueueInteractive serves latency-sensitive user-requested refreshes.
	QueueInteractive = "interactive"
	// QueueEvent serves webhook-originated refreshes.
	QueueEvent = "event"
	// QueueSweep serves bounded-staleness refreshes.
	QueueSweep = "sweep"
	// QueueReconcile serves sweep state-machine and gap-healing work.
	QueueReconcile = "reconcile"
	// QueueDrift serves sampled semantic-drift detection.
	QueueDrift = "drift"
	// QueuePruner serves retention deletion work.
	QueuePruner = "pruner"
)
View Source
const (
	// KindRefreshPR refreshes one pull request.
	KindRefreshPR = "refresh_pr"
	// KindRefreshRepository refreshes one repository.
	KindRefreshRepository = "refresh_repository"
	// KindRefreshRepoRules refreshes repository rules.
	KindRefreshRepoRules = "refresh_repo_rules"
	// KindRefreshStack refreshes one stack.
	KindRefreshStack = "refresh_stack"
	// KindRefreshChecks refreshes check runs for one head SHA.
	KindRefreshChecks = "refresh_checks"
	// KindRefreshBranch refreshes branch-dependent entities.
	KindRefreshBranch = "refresh_branch"
	// KindResolveStackMembership resolves a pull request's stack ownership.
	KindResolveStackMembership = "resolve_stack_membership"
	// KindBackfillRepoPage continues one repository backfill.
	KindBackfillRepoPage = "backfill_repo_page"
	// KindBackfillInstallation continues installation repository discovery.
	KindBackfillInstallation = "backfill_installation_page"
)

Variables

This section is empty.

Functions

func InsertRefreshesTx

func InsertRefreshesTx(
	ctx context.Context,
	tx pgx.Tx,
	client *river.Client[pgx.Tx],
	specs []RefreshSpec,
	queueName string,
) error

InsertRefreshesTx atomically advances durable generations and inserts follow-up pointers. Stack diffs, branch fan-out, and backfill all use this path so running-state coalescing keeps the same meaning everywhere.

func NewBackfillInsertOpts

func NewBackfillInsertOpts() *river.InsertOpts

NewBackfillInsertOpts returns interactive-queue uniqueness for backfills.

func NewBackfillInsertOptsForQueue

func NewBackfillInsertOptsForQueue(queueName string) *river.InsertOpts

NewBackfillInsertOptsForQueue returns backfill uniqueness for queueName.

func NewClient

func NewClient(
	pool *pgxpool.Pool,
	options ...ClientOption,
) (*river.Client[pgx.Tx], error)

NewClient builds a River client for the selected component queues and worker registrars. Without WithQueues it owns the three priority queues: interactive, event, and sweep.

func NewRefreshInsertOpts

func NewRefreshInsertOpts(scheduledAt time.Time) *river.InsertOpts

NewRefreshInsertOpts is the one supported uniqueness definition for refresh work. River requires running in this mask; a durable generation handles signals that coalesce while a job runs.

func NewRefreshInsertOptsForQueue

func NewRefreshInsertOptsForQueue(
	queueName string,
	scheduledAt time.Time,
) *river.InsertOpts

NewRefreshInsertOptsForQueue returns refresh uniqueness for queueName.

Types

type BackfillInstallationPageArgs

type BackfillInstallationPageArgs struct {
	InstallationID int64  `json:"installation_id"`
	Phase          string `json:"phase"`
	Page           int    `json:"page"`
}

BackfillInstallationPageArgs identifies one repository-discovery page.

func NewBackfillInstallationPageArgs

func NewBackfillInstallationPageArgs(
	installationID int64,
	phase string,
	page int,
) BackfillInstallationPageArgs

NewBackfillInstallationPageArgs constructs a discovery backfill pointer.

func (BackfillInstallationPageArgs) Kind

Kind returns the River job kind.

type BackfillRepoPageArgs

type BackfillRepoPageArgs struct {
	InstallationID int64  `json:"installation_id"`
	RepoFullName   string `json:"repo"`
	Phase          string `json:"phase"`
	Page           int    `json:"page"`
}

BackfillRepoPageArgs identifies one resumable repository backfill page.

func NewBackfillRepoPageArgs

func NewBackfillRepoPageArgs(
	installationID int64,
	repoFullName string,
	phase string,
	page int,
) BackfillRepoPageArgs

NewBackfillRepoPageArgs constructs a resumable repository backfill pointer.

func (BackfillRepoPageArgs) Kind

Kind returns the River job kind.

type ClientOption

type ClientOption func(*clientOptions)

ClientOption customizes River workers, queues, schedules, and observers.

func WithDeadlineObserver

func WithDeadlineObserver(observer DeadlineObserver) ClientOption

WithDeadlineObserver installs refresh-deadline instrumentation.

func WithNow

func WithNow(now func() time.Time) ClientOption

WithNow supplies worker time for deterministic testing.

func WithPeriodicJobs

func WithPeriodicJobs(jobs ...*river.PeriodicJob) ClientOption

WithPeriodicJobs installs leader-elected River schedules supplied by the enabled serve roles.

func WithPlugins

func WithPlugins(plugins ...rivertype.Plugin) ClientOption

WithPlugins installs River plugins on inserts, workers, and internal hooks.

func WithQueueMaxWorkers

func WithQueueMaxWorkers(queueName string, maxWorkers int) ClientOption

WithQueueMaxWorkers is primarily a deterministic test seam. Production keeps the reserved defaults below.

func WithQueues

func WithQueues(names ...string) ClientOption

WithQueues limits a started client to the component queues owned by its enabled roles. Producer-only clients may pass no names and are never started, while combined roles pass the union of their queue families.

func WithRefreshHandler

func WithRefreshHandler(handler RefreshHandler) ClientOption

WithRefreshHandler installs the authoritative refresh implementation.

func WithRefreshObserver

func WithRefreshObserver(observer RefreshObserver) ClientOption

WithRefreshObserver installs authoritative-fetch instrumentation.

func WithWorkerRegistrar

func WithWorkerRegistrar(registrar func(*river.Workers)) ClientOption

WithWorkerRegistrar lets milestone packages own their typed River args and workers without making queue import sweep/drift and creating a package cycle.

func WithoutRefreshWorkers

func WithoutRefreshWorkers() ClientOption

WithoutRefreshWorkers is for a worker-only role such as the retention pruner. Producer clients keep the default registrations so River can validate refresh args at insertion time.

type DeadlineObserver

type DeadlineObserver interface {
	RefreshDeadlineMissed(
		context.Context,
		string,
		string,
		time.Time,
		time.Time,
	)
}

DeadlineObserver receives completed refreshes that missed reconciliation deadlines.

type DeadlineObservers

type DeadlineObservers []DeadlineObserver

DeadlineObservers fans deadline misses out in declaration order.

func (DeadlineObservers) RefreshDeadlineMissed

func (observers DeadlineObservers) RefreshDeadlineMissed(
	ctx context.Context,
	kind string,
	key string,
	deadline time.Time,
	completedAt time.Time,
)

type LogDeadlineObserver

type LogDeadlineObserver struct{}

LogDeadlineObserver logs reconciliation deadline misses.

func (LogDeadlineObserver) RefreshDeadlineMissed

func (LogDeadlineObserver) RefreshDeadlineMissed(
	_ context.Context,
	kind string,
	key string,
	deadline time.Time,
	completedAt time.Time,
)

type RefreshArgs

type RefreshArgs struct {
	PointerKind string `json:"kind"`
	Key         string `json:"key"`
}

RefreshArgs is the complete durable job pointer. It intentionally contains no webhook or entity payload (SYNC_ENGINE §8 and C-I4).

type RefreshBranchArgs

type RefreshBranchArgs struct{ RefreshArgs }

RefreshBranchArgs points at one repository branch.

func NewRefreshBranchArgs

func NewRefreshBranchArgs(key string) RefreshBranchArgs

NewRefreshBranchArgs constructs a branch refresh pointer.

func (RefreshBranchArgs) Kind

func (RefreshBranchArgs) Kind() string

Kind returns the River job kind.

type RefreshChecksArgs

type RefreshChecksArgs struct{ RefreshArgs }

RefreshChecksArgs points at one repository head SHA.

func NewRefreshChecksArgs

func NewRefreshChecksArgs(key string) RefreshChecksArgs

NewRefreshChecksArgs constructs a checks refresh pointer.

func (RefreshChecksArgs) Kind

func (RefreshChecksArgs) Kind() string

Kind returns the River job kind.

type RefreshGeneration

type RefreshGeneration struct {
	Spec       RefreshSpec
	Generation int64
}

RefreshGeneration pairs a deduplicated refresh spec with its durable generation after insertion.

func InsertRefreshesTxReturning

func InsertRefreshesTxReturning(
	ctx context.Context,
	tx pgx.Tx,
	client *river.Client[pgx.Tx],
	specs []RefreshSpec,
	queueName string,
) ([]RefreshGeneration, error)

InsertRefreshesTxReturning performs InsertRefreshesTx and returns each deduplicated spec's new durable generation.

type RefreshHandler

type RefreshHandler interface {
	RefreshPR(context.Context, RefreshRequest) error
	RefreshRepository(context.Context, RefreshRequest) error
	RefreshRepoRules(context.Context, RefreshRequest) error
	RefreshStack(context.Context, RefreshRequest) error
	RefreshChecks(context.Context, RefreshRequest) error
	RefreshBranch(context.Context, RefreshRequest) error
	ResolveStackMembership(context.Context, RefreshRequest) error
	BackfillRepoPage(context.Context, BackfillRepoPageArgs) error
	BackfillInstallationPage(
		context.Context,
		BackfillInstallationPageArgs,
	) error
}

RefreshHandler is implemented by internal/fetch. Keeping this interface in queue avoids coupling durable job definitions to GitHub/cache internals.

type RefreshObservation

type RefreshObservation struct {
	Kind             string
	Queue            string
	EventReceivedAt  time.Time
	CacheCommittedAt time.Time
	StartedAt        time.Time
	CompletedAt      time.Time
	Err              error
}

RefreshObservation describes one authoritative fetch attempt. C-Q2's event-to-cache latency is populated only for event-originated generations.

type RefreshObserver

type RefreshObserver interface {
	RefreshFinished(context.Context, *RefreshObservation)
}

RefreshObserver receives completed authoritative-fetch observations.

type RefreshPRArgs

type RefreshPRArgs struct{ RefreshArgs }

RefreshPRArgs points at one pull request.

func NewRefreshPRArgs

func NewRefreshPRArgs(key string) RefreshPRArgs

NewRefreshPRArgs constructs a pull-request refresh pointer.

func (RefreshPRArgs) Kind

func (RefreshPRArgs) Kind() string

Kind returns the River job kind.

type RefreshRepoRulesArgs

type RefreshRepoRulesArgs struct{ RefreshArgs }

RefreshRepoRulesArgs points at one repository ruleset.

func NewRefreshRepoRulesArgs

func NewRefreshRepoRulesArgs(key string) RefreshRepoRulesArgs

NewRefreshRepoRulesArgs constructs a repository-rules refresh pointer.

func (RefreshRepoRulesArgs) Kind

Kind returns the River job kind.

type RefreshRepositoryArgs

type RefreshRepositoryArgs struct{ RefreshArgs }

RefreshRepositoryArgs points at one repository.

func NewRefreshRepositoryArgs

func NewRefreshRepositoryArgs(key string) RefreshRepositoryArgs

NewRefreshRepositoryArgs constructs a repository refresh pointer.

func (RefreshRepositoryArgs) Kind

Kind returns the River job kind.

type RefreshRequest

type RefreshRequest struct {
	Args  RefreshArgs
	Queue string
}

RefreshRequest gives a handler its durable pointer and owning queue.

type RefreshSpec

type RefreshSpec struct {
	Kind            string
	Key             string
	ScheduledAt     time.Time
	Deadline        time.Time
	EventReceivedAt time.Time
}

RefreshSpec describes one desired refresh generation and optional timing metadata.

type RefreshStackArgs

type RefreshStackArgs struct{ RefreshArgs }

RefreshStackArgs points at one stack.

func NewRefreshStackArgs

func NewRefreshStackArgs(key string) RefreshStackArgs

NewRefreshStackArgs constructs a stack refresh pointer.

func (RefreshStackArgs) Kind

func (RefreshStackArgs) Kind() string

Kind returns the River job kind.

type ResolveStackMembershipArgs

type ResolveStackMembershipArgs struct{ RefreshArgs }

ResolveStackMembershipArgs points at a pull request requiring resolution.

func NewResolveStackMembershipArgs

func NewResolveStackMembershipArgs(key string) ResolveStackMembershipArgs

NewResolveStackMembershipArgs constructs a membership-resolution pointer.

func (ResolveStackMembershipArgs) Kind

Kind returns the River job kind.

Jump to

Keyboard shortcuts

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