batch

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package batch implements bors-style batch testing: build a single merge branch from N queued PRs, fast-forward the target on green, and bisect on red. All state lives on one pg.Batch row so the loop is restart-safe.

Index

Constants

View Source
const BranchPrefix = merge.BranchPrefix + "batch/"

BranchPrefix is the namespace for batch merge branches.

View Source
const MaxFFRetries = 3

MaxFFRetries caps consecutive ErrNotFastForward rebuilds before the remaining current members are ejected with an actionable error.

Variables

This section is empty.

Functions

func BranchName

func BranchName(id int64) string

BranchName returns the canonical batch branch name.

func TimedOut

func TimedOut(b *pg.Batch, timeout time.Duration) bool

TimedOut reports whether the batch has been testing longer than timeout.

Types

type Engine

type Engine struct {
	Forge       forge.Forge
	Queue       *queue.Service
	Owner       string
	Repo        string
	RepoID      int64
	ExternalURL string

	BatchMax       int
	BisectMaxSteps int
	CheckTimeout   time.Duration
	FallbackChecks []string
	MergeLabel     string

	// MergedPoll controls ensureMergedOrClose. Defaults: 200ms × 50 = 10s.
	MergedPollInterval time.Duration
	MergedPollAttempts int

	// Advance is called whenever a batch finishes so the next root can be
	// formed without waiting for the poll tick. Optional.
	Advance func()
	// contains filtered or unexported fields
}

Engine drives the batch lifecycle for one repository. The pg.Batch row is the source of truth; the mutex serialises every public entry point so the webhook handler and poller cannot mutate the same batch concurrently.

func (*Engine) Build

func (e *Engine) Build(ctx context.Context, b *pg.Batch) error

Build constructs the batch branch by merging current_ids onto the target tip. Conflicting members are ejected and construction continues. On success the batch transitions to testing and every current entry's merge_branch_* is set to the batch branch so the existing SHA-routing keeps working.

func (*Engine) Enabled

func (e *Engine) Enabled() bool

Enabled reports whether batching is active. BatchMax==1 keeps the legacy single-PR path byte-for-byte intact.

func (*Engine) FormAndBuild

func (e *Engine) FormAndBuild(ctx context.Context, targetBranch string) (*pg.Batch, error)

FormAndBuild forms a new root batch from the queued head and builds its branch. Returns nil when there is nothing to do (queue empty or a live batch already exists). Safe to call on every poll tick.

func (*Engine) HandleCheck

func (e *Engine) HandleCheck(ctx context.Context, entry *pg.QueueEntry, checkCtx string, state pg.CheckState, targetURL string) error

HandleCheck implements monitor.BatchHandler. It is the single entry point from the check pipeline into the batch engine: lock, guard against stale SHAs, and only then persist the check and evaluate. Persisting after the guard is what stops a late event for a superseded build from polluting the ledger that decides the current one.

func (*Engine) HandleFail

func (e *Engine) HandleFail(ctx context.Context, b *pg.Batch, failedCheck, targetURL string) error

HandleFail bisects: split current, push the second half, rebuild the first. A failing singleton is ejected with the failed check attributed.

func (*Engine) HandlePass

func (e *Engine) HandlePass(ctx context.Context, b *pg.Batch) error

HandlePass lands current_ids by fast-forwarding the target branch to the tested SHA, then pops the next pending slice.

func (*Engine) HandleTimeout

func (e *Engine) HandleTimeout(ctx context.Context, targetBranch string, batchID int64) error

HandleTimeout treats a CI timeout as a batch failure. The batch is reloaded under the lock so a poller snapshot that raced a webhook-driven rebuild cannot bisect a stale view.

func (*Engine) LiveBranchNames

func (e *Engine) LiveBranchNames(ctx context.Context) ([]string, error)

LiveBranchNames returns the branch name of every live batch for the repo so the orphan-branch reaper can spare them.

func (*Engine) OnMemberRemoved

func (e *Engine) OnMemberRemoved(ctx context.Context, targetBranch string, batchID, entryID int64) error

OnMemberRemoved drops an entry from the live batch (push/close/retarget/ cancel). The caller is responsible for cancelling automerge / commenting on the PR; this function only adjusts batch bookkeeping and rebuilds when the removed entry was on the branch under test.

func (*Engine) ReconcileLive

func (e *Engine) ReconcileLive(ctx context.Context) error

ReconcileLive resumes batches found at startup: forming → rebuild; testing → re-sync each current entry's merge_branch_* from the batch row so a crash between Build's SaveBatch and SetMergeBranch cannot strand the batch with no entry routing the current SHA.

type MemberBucket

type MemberBucket string

MemberBucket is a member's position within a live batch for UI display.

const (
	BucketCurrent MemberBucket = "current"
	BucketPending MemberBucket = "pending"
	BucketLanded  MemberBucket = "landed"
	BucketEjected MemberBucket = "ejected"
)

func Bucket

func Bucket(b *pg.Batch, id int64) MemberBucket

Bucket reports which slice of b the entry id is in.

Jump to

Keyboard shortcuts

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