background

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package background keeps local GitHub metadata fresh without a generation queue, model backend, checkout export or hosted baum service. It hands discovery snapshots to Service.Discovered and nothing else: automatic generation is the daemon's separate scheduler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Saved

func Saved(ctx context.Context, clone repos.Clone) ([]int, error)

Types

type Local

type Local struct {
	Client assemble.GitHub
	Config config.Config
}

func (Local) Refresh

func (l Local) Refresh(ctx context.Context, clone repos.Clone, number int) (result discovery.Observation, returnedErr error)

type Problem

type Problem struct {
	PR     int    `json:"pr"`
	Reason string `json:"reason"`
}

type Registry

type Registry interface {
	Repositories(context.Context) ([]repos.Repository, error)
}

type Retention

type Retention struct {
	Log *slog.Logger
}

Retention reconciles the refs that keep saved review versions' commits in a clone (reviewrefs.Reconcile, within reviewrefs.DefaultLimits). A clone that cannot be opened or reconciled is skipped with a log line.

func (Retention) Retain

func (r Retention) Retain(ctx context.Context, clone repos.Clone) (bool, error)

type Service

type Service struct {
	Registry  Registry
	Discovery Discovery
	// Refresh must only read GitHub/local evidence and CAS-publish the latest
	// saved review. It must never enqueue or invoke generation.
	Refresh func(context.Context, repos.Clone, int) (discovery.Observation, error)
	Saved   func(context.Context, repos.Clone) ([]int, error)
	// Discovered receives every snapshot a discovery poll returned without
	// error. The daemon passes them to its automatic generation scheduler
	// (internal/automatic), which alone decides whether to queue a job; this
	// service never enqueues or invokes generation itself.
	Discovered func(context.Context, discovery.Snapshot)
	// Retain reconciles a clone's retained review refs with its stores and
	// reports whether a bound left work for another pass (Retention.Retain);
	// nil skips it. Sync calls it per common git directory, see retainDue.
	Retain   func(context.Context, repos.Clone) (bool, error)
	Changed  func()
	Now      func() time.Time
	Interval time.Duration
	// contains filtered or unexported fields
}

func (*Service) Handler

func (s *Service) Handler() http.Handler

func (*Service) Limited

func (s *Service) Limited(host string, until time.Time)

Limited records a rate limit another reader of the account's GitHub budget hit, so refreshes wait it out too.

func (*Service) Paused

func (s *Service) Paused(host string) time.Time

Paused is when the host's rate limit lets refreshes resume, for another reader of the same account's GitHub budget, such as the PR page's facts (internal/facts), to wait it out too.

func (*Service) RefreshInterval

func (s *Service) RefreshInterval() time.Duration

RefreshInterval is how often the background refresh polls.

func (*Service) RefreshNow

func (s *Service) RefreshNow(ctx context.Context, clone repos.Clone, numbers []int) ([]discovery.Observation, error)

RefreshNow refreshes some pull requests of one clone at once, as Sync refreshes each of them, outside Sync's schedule: a hook event said they changed. It honors the host's rate pause, which a rate-limited refresh here extends for Sync too, and returns the observations it made. It never enqueues or invokes generation.

func (*Service) ResetIdentity

func (s *Service) ResetIdentity()

ResetIdentity drops credential-dependent backoff without waiting for an old network pass. Its late state/rate writes are fenced by the captured epoch.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run starts immediately in its caller's goroutine. The host runs it separately from HTTP startup; a slow/offline GitHub never holds the cached inbox hostage. One worker bounds both GitHub and local session reads across all repositories.

func (*Service) Sync

func (s *Service) Sync(ctx context.Context)

Sync is a single serialized scheduling pass, exposed for deterministic tests. Discovery itself owns conditional requests and credential-wide rate budgets. It polls every due repository first, so no repository's pull requests wait behind another's reads, then reads the saved pull requests that are due, those GitHub reported changed first, within refreshBudget.

type State

type State struct {
	Problems    []Problem `json:"problems,omitempty"`
	Repository  string    `json:"repository"`
	LastSuccess time.Time `json:"last_success"`
	NextRefresh time.Time `json:"next_refresh"`
	Error       string    `json:"error,omitempty"`
	Failures    int       `json:"failures"`
}

Jump to

Keyboard shortcuts

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