poller

package
v0.218.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package poller is the ingester a self-hosted bench needs by default.

Without a GitHub App there is no webhook to receive, so the daemon asks GitHub instead: once per interval it reads every repository in the local machine's published inventory and compares the answer with what it saw last time. A moved default branch or a renamed repository produces exactly the repositoryevent.Event the webhook path would have produced, enqueued for the local machine through the hub's own repository-event store. The daemon downstream cannot tell the two apart, which is the point: polling and webhooks are two ways to fill one queue.

Event IDs are derived from repository, reason and target, so a replay after a crash deduplicates through the store's marker collection rather than fast-forwarding a clone twice.

Index

Constants

View Source
const (
	// DefaultAPIBaseURL is GitHub's public API. A test points this at an
	// httptest server instead.
	DefaultAPIBaseURL = "https://api.github.com"
	// DefaultInterval matches hub.github.poll_interval's default.
	DefaultInterval = 60 * time.Second
	// MaxBackoff bounds the exponential retreat after a transient GitHub
	// failure. Ten minutes is long enough to ride out an incident and short
	// enough that an operator who fixes their token does not have to restart
	// the daemon to see it work.
	MaxBackoff = 10 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Client performs the GitHub requests.
	Client *http.Client
	// APIBaseURL is GitHub's API origin. Empty means DefaultAPIBaseURL.
	APIBaseURL string
	// Token returns the operator's GitHub token. It is called once per tick
	// so that rotating the token file takes effect without a restart, and its
	// result is never narrated, logged, or stored.
	Token func() (string, error)
	// Snapshots is where the local machine's repository inventory is read
	// from: the poller polls exactly what the machine publishes.
	Snapshots hub.MachineSnapshotStore
	// Events receives the enqueued events.
	Events hub.RepositoryEventStore
	// Observations is the poller's memory of what it last saw.
	Observations hub.PollObservationStore
	// Machine is the local machine every polled event is queued for.
	Machine hub.Machine
	// Interval is the gap between ticks. Zero means DefaultInterval.
	Interval time.Duration
	// Now and Sleep exist so a test drives time instead of waiting for it.
	Now   func() time.Time
	Sleep func(context.Context, time.Duration) error
	// Narrate receives one line per repository observed, plus one line for a
	// failure that ends a tick before any repository is read.
	Narrate func(narrate.Line)
	// Covered reports whether an installed GitHub App already delivers
	// webhooks for a repository, which the poller then skips. Nil means
	// nothing is covered, which is the whole of this feature's default
	// journey; webhook mode supplies it.
	Covered func(repository string) bool
}

Options configures a Poller. Client, Snapshots, Events, Observations and Machine are required; everything else has a working default.

type Poller

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

Poller reads GitHub on an interval and enqueues what changed.

func New

func New(options Options) *Poller

New returns a Poller with every optional field defaulted.

func (*Poller) Repositories

func (poller *Poller) Repositories() int

Repositories is how many repositories the last tick actually polled, which `wb daemon status` reports. It is read from another goroutine.

func (*Poller) Run

func (poller *Poller) Run(ctx context.Context) error

Run ticks until ctx ends. It returns nil on a cancelled context: a stopped poller is a normal shutdown, not a failure the daemon should report.

func (*Poller) Tick

func (poller *Poller) Tick(ctx context.Context) time.Duration

Tick performs one pass over the inventory and returns how long to wait before the next one: the configured interval normally, the remaining rate-limit window when GitHub's budget is nearly spent, or the current backoff after a transient failure.

Jump to

Keyboard shortcuts

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