Documentation
¶
Overview ¶
Package check holds the required checks of a ref, the results that a runner posts, and the delivery of check requests.
Index ¶
- Constants
- Variables
- func KeyBase(c Check, baseTree string) string
- func ValidName(name string) bool
- type Check
- type Clock
- type LeasedError
- type Manager
- func (m *Manager) EnsureAfter(ctx context.Context, mark int64, repo, tree, commit, base, baseTree string, ...) error
- func (m *Manager) Mark(ctx context.Context) (int64, error)
- func (m *Manager) OnResult(f func(repo string))
- func (m *Manager) Post(ctx context.Context, repo, kid string, p Posted) error
- func (m *Manager) Runner(repo string) (Runner, bool)
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Verdict(ctx context.Context, repo, tree, baseTree string, c Check, mark int64) (Verdict, error)
- func (m *Manager) Wait()
- type Posted
- type Request
- type Result
- type Runner
- type State
- type Status
- type Store
- type Verdict
Constants ¶
const ( Pending = wardapi.CheckPending Pass = wardapi.CheckPass Fail = wardapi.CheckFail Flaky = wardapi.CheckFlaky )
const ( StatusPass = runnerproto.Pass StatusFail = runnerproto.Fail )
const (
// FilePath is the check file at the tip of a target ref.
FilePath = ".ward/checks.json"
)
const KeyChange = "change"
KeyChange is the value of the key of a check whose result belongs to the base tree and the tree of a change.
const ModePull = "pull"
ModePull is the one dispatch mode. An entry may name it, so a list written for an earlier version still loads.
const PollEvery = 500 * time.Millisecond
Variables ¶
var ( // ErrInvalid means that a posted result breaks a rule of the body. ErrInvalid = errors.New("check: invalid result") // ErrUnknownRequest means that no request has the posted request_id. ErrUnknownRequest = errors.New("check: unknown request") // ErrOtherRepo means that the request belongs to another repository. ErrOtherRepo = errors.New("check: request of another repository") // ErrNotRegistered means that the poster is not a runner that leased the request of a pull repository. ErrNotRegistered = errors.New("check: runner not registered for the repository") )
var ErrNoRunner = errors.New("check: no runner for the repository")
ErrNoRunner means that no runner is configured for the repository.
Functions ¶
Types ¶
type Check ¶
type Check = runnerproto.Check
Check is one required check. The runner runs Run at the root of the tree.
type LeasedError ¶ added in v0.8.0
LeasedError means that a runner holds a live lease on the request, so the request is not replaced. Until is the end of the lease.
func (*LeasedError) Error ¶ added in v0.8.0
func (e *LeasedError) Error() string
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps the results and sends the check requests. Each repository has one workflow, check:<repo>, that replaces a late request.
func (*Manager) EnsureAfter ¶ added in v0.13.0
func (m *Manager) EnsureAfter(ctx context.Context, mark int64, repo, tree, commit, base, baseTree string, c Check) error
EnsureAfter makes sure that a request for check c of tree is open, and starts its delivery when it opens one. It opens no request when the key has a fail after the mark, so a fail that arrives while a land reads its verdicts does not make a second request.
func (*Manager) Mark ¶
Mark returns the position after the newest result. A fail counts for a land only when it is after its mark.
func (*Manager) Post ¶
Post records a result that the runner kid posted for a repository. A second result for a request changes nothing. For a pull repository, kid must be one of the kids of the repository and must have leased the request.
func (*Manager) Start ¶
Start resumes the workflow of every repository that has an open request. The workflows stop when ctx ends.
type Request ¶
type Request struct {
ID string
Repo string
Tree string
Commit string
Check Check
Hash string
Env string
Base string
BaseTree string
// KeyBase is the base tree of the result key of a change-keyed check, and empty for the default key.
KeyBase string
AcceptedAt time.Time
Open bool
// FailedAfter, when set, makes OpenRequest open no request while the key has a fail with a result ID above it.
FailedAfter *int64
}
Request is one check request to a runner. It is open until a result or a newer request for its key ends it.
type Result ¶
type Result struct {
ID int64
RequestID string
Repo string
Tree string
Hash string
Env string
KeyBase string
Status Status
Summary string
LogURL string
}
Result is a fact about the content of a tree. Its ID orders results across the store.
type Runner ¶
type Runner struct {
Repo string `json:"repo"`
Mode string `json:"mode,omitempty"`
Kids []string `json:"kids"`
MinIsolation string `json:"min_isolation,omitempty"`
Env string `json:"env"`
}
Runner names the runners that serve the check requests of one repository. Each kid is a runner identity that polls ward for a lease.
func ParseRunners ¶
ParseRunners decodes and checks the WARD_RUNNERS list. It rejects an unknown field.
type Store ¶
type Store interface {
// OpenRequest returns the open request for the key of r. With no open request and no pass for the key, it stores r and returns it with true.
OpenRequest(ctx context.Context, r Request) (Request, bool, error)
Request(ctx context.Context, id string) (Request, bool, error)
OpenRequests(ctx context.Context) ([]Request, error)
// Supersede closes the request old and stores next, an open request for the same key. It does nothing and returns false
// when old is no longer open or the key has a pass. It does nothing and returns a *LeasedError when a runner holds a
// lease on old that is live at now.
Supersede(ctx context.Context, old string, next Request, now time.Time) (bool, error)
// AddResult stores a result and closes its request. A pass also closes every other open request for the key.
// It returns false and changes nothing when the request already has a result.
AddResult(ctx context.Context, r Result) (bool, error)
// Results returns the results of one key, oldest first.
Results(ctx context.Context, repo, tree, hash, env, keyBase string) ([]Result, error)
MaxResultID(ctx context.Context) (int64, error)
// Lease gives kid, under leaseID, the oldest open request of one of repos that has no live lease, until the time until.
// A lease that passed its time is dead, so its request is leasable again with the same ID. The returned request has
// AcceptedAt set to now.
Lease(ctx context.Context, repos []string, kid, leaseID string, now, until time.Time) (Request, bool, error)
// RenewLease moves the end of a lease that kid holds. It returns false when the request is closed, when its repository
// is not in repos, when a newer lease replaced the lease, or when kid does not hold it.
RenewLease(ctx context.Context, leaseID, kid string, repos []string, until time.Time) (bool, error)
// Leased reports whether kid has held a lease on the request.
Leased(ctx context.Context, requestID, kid string) (bool, error)
}
Store is the transactional state of requests and results. Each method that writes is one transaction.