dispatch

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package dispatch classifies durable webhook hints and coalesces them into River refresh jobs. It never treats webhook payload data as cache truth.

Index

Constants

View Source
const (
	ActionAny     = "*"
	PriorityEvent = queue.QueueEvent
)
View Source
const (
	// MaxDebounce is C-Q2's hard event-to-cache debounce ceiling.
	MaxDebounce = 15 * time.Second

	// DefaultBranchReconcilePageSize matches the GraphQL nodes batch ceiling.
	DefaultBranchReconcilePageSize = 25
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchBulkObserver added in v0.5.0

type BranchBulkObserver interface {
	BranchBulkApplied(
		context.Context,
		int,
		int,
		int,
		int,
		int64,
	)
}

BranchBulkObserver distinguishes local branch hint application from remote entity refresh work without attaching repository or entity keys as tags.

type Classifier

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

Classifier applies an injected rule table.

func DefaultClassifier

func DefaultClassifier() Classifier

func NewClassifier

func NewClassifier(rules []Rule) Classifier

func (Classifier) Classify

func (c Classifier) Classify(event string, body []byte) ([]Intent, error)

Classify parses only events that have a configured rule. Unknown events are successful no-ops even when their bodies are malformed (C-I5).

func (Classifier) ClassifyContent

func (c Classifier) ClassifyContent(
	event string,
	contentType string,
	body []byte,
) ([]Intent, error)

ClassifyContent classifies a webhook body in either GitHub-supported wire format. It is primarily exposed for conformance tests; the dispatcher reads the content type captured by ingress before calling the same path.

type Config

type Config struct {
	BatchSize      int
	MaxAttempts    int
	Debounce       time.Duration
	PollInterval   time.Duration
	Now            func() time.Time
	Classifier     Classifier
	Observer       Observer
	Tracer         trace.Tracer
	BranchPageSize int
}

Config controls dispatcher batching, poison tolerance, and bounded debounce.

type Dispatcher

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

Dispatcher owns the delivery → River transaction boundary (C-P2).

func New

func New(
	pool *pgxpool.Pool,
	riverClient *river.Client[pgx.Tx],
	config Config,
) (*Dispatcher, error)

New validates config and constructs a delivery dispatcher.

func (*Dispatcher) DispatchBatch

func (d *Dispatcher) DispatchBatch(
	ctx context.Context,
) (count int, resultErr error)

DispatchBatch claims, classifies, enqueues, and finishes one batch. Each attempt uses one pgx transaction shared by sqlc and River; a contended generation lock rolls that attempt back before retrying the complete batch.

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context) error

Run continuously drains available batches and polls when idle.

type Intent

type Intent struct {
	Kind     string `json:"kind"`
	Key      string `json:"key"`
	Priority string `json:"priority"`
}

Intent is a dispatch decision, not an entity payload.

type Observer

type Observer interface {
	DispatchBatch(context.Context, int)
}

Observer is M6's C-P2/C-I5 observability seam. Implementations run only after the delivery batch and its River pointers commit.

type Rule

type Rule struct {
	Event         string `json:"event" yaml:"event"`
	Action        string `json:"action" yaml:"action"`
	Target        Target `json:"target" yaml:"target"`
	StackedTarget Target `json:"stacked_target,omitempty" yaml:"stacked_target,omitempty"`
}

Rule is the config-driven event/action → refresh mapping. StackedTarget adds stack maintenance when a pull request payload carries the stack preview object (SYNC_ENGINE §2.1); the direct PR refresh remains authoritative for PR-scoped connections such as changed files.

func DefaultRules

func DefaultRules() []Rule

DefaultRules is data rather than event-specific control flow so preview webhook changes can be accommodated by changing the table.

func LoadRulesFile

func LoadRulesFile(path string) ([]Rule, error)

LoadRulesFile makes observed-payload findings a reviewed data change rather than an event-specific code branch. YAML is a superset of the shipped JSON shape, so either format is accepted.

type Target

type Target string

Target names a declarative key extractor used by a Rule.

const (
	TargetPullRequest Target = "pull_request"
	TargetStack       Target = "stack"
	TargetChecks      Target = "checks"
	TargetBranch      Target = "branch"
	// TargetCodeowners routes only a default-branch push that touched one of
	// GitHub's three effective CODEOWNERS locations. It intentionally reuses
	// refresh_branch so ordinary push and source-change hints coalesce.
	TargetCodeowners Target = "codeowners"
	// TargetResolveStackMembership carries only the PR key. Its M3 worker
	// consults cached membership and refreshes both the old and new stacks.
	TargetResolveStackMembership Target = "resolve_stack_membership"
)

type UnmatchedEventObserver

type UnmatchedEventObserver interface {
	DispatchUnmatchedEvent(context.Context, string)
}

UnmatchedEventObserver is an optional coverage-gap signal. Dispatcher also logs every committed delivery that matched zero configured rules so the signal remains visible when the batch observer does not implement this interface.

Jump to

Keyboard shortcuts

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