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
- func BranchName(id int64) string
- func TimedOut(b *pg.Batch, timeout time.Duration) bool
- type Engine
- func (e *Engine) Build(ctx context.Context, b *pg.Batch) error
- func (e *Engine) Enabled() bool
- func (e *Engine) FormAndBuild(ctx context.Context, targetBranch string) (*pg.Batch, error)
- func (e *Engine) HandleCheck(ctx context.Context, entry *pg.QueueEntry, checkCtx string, ...) error
- func (e *Engine) HandleFail(ctx context.Context, b *pg.Batch, failedCheck, targetURL string) error
- func (e *Engine) HandlePass(ctx context.Context, b *pg.Batch) error
- func (e *Engine) HandleTimeout(ctx context.Context, targetBranch string, batchID int64) error
- func (e *Engine) LiveBranchNames(ctx context.Context) ([]string, error)
- func (e *Engine) OnMemberRemoved(ctx context.Context, targetBranch string, batchID, entryID int64) error
- func (e *Engine) ReconcileLive(ctx context.Context) error
- type MemberBucket
Constants ¶
const BranchPrefix = merge.BranchPrefix + "batch/"
BranchPrefix is the namespace for batch merge branches.
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 ¶
BranchName returns the canonical batch branch name.
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 ¶
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 ¶
Enabled reports whether batching is active. BatchMax==1 keeps the legacy single-PR path byte-for-byte intact.
func (*Engine) FormAndBuild ¶
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 ¶
HandleFail bisects: split current, push the second half, rebuild the first. A failing singleton is ejected with the failed check attributed.
func (*Engine) HandlePass ¶
HandlePass lands current_ids by fast-forwarding the target branch to the tested SHA, then pops the next pending slice.
func (*Engine) HandleTimeout ¶
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 ¶
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 ¶
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" )