Documentation
¶
Overview ¶
Package gate grants the gates: shared resources (code generation, the local stack, an end-to-end run, a paid model run) that one holder uses at a time, granted only while the machine is not under pressure and has the memory the command peaked at. Djinn's own requests to merge a task's work, settle a merge or check a push go first, the first come first; then the others, the first wish of the rank first (Q26), then the work of its first azima (Task.rank). A holder keeps its gate until it gives it back, its connection ends, its process ends or its timeout passes: none is taken back for a request that goes first. A lit ifrit's gate has no timeout: it is held until the ifrit goes out or ends, at its out time at the latest (T51), and goes to no one first for it. A gate held outside a running worker takes a worker's slot.
Index ¶
- Constants
- func Handler(g *Gates) (string, http.Handler)
- func Name(s string) string
- func Run(ctx context.Context, client machinev1connect.GateServiceClient, ...) (int, error)
- type Command
- type Costs
- type Gates
- func (g *Gates) AddInterval(iv *machinev1.GateInterval)
- func (g *Gates) Freed(f func())
- func (g *Gates) Held(taskID string) []string
- func (g *Gates) IfritWaits() map[string][]string
- func (g *Gates) Intervals(cutoff time.Time) []*machinev1.GateInterval
- func (g *Gates) List() []State
- func (g *Gates) Measure(every time.Duration, read Read)
- func (g *Gates) Outside() (n, merges int)
- func (g *Gates) ProjectResolver(fn func(taskID, dir string) string)
- func (g *Gates) Take(ctx context.Context, r Request, waiting func(why string)) (*Hold, error)
- func (g *Gates) Track(f func(pid int, taskID string) func())
- func (g *Gates) Waiting(taskID string) []string
- type Hold
- type Machine
- type Read
- type Request
- type State
- type Tasks
Constants ¶
const DefaultTimeout = time.Hour
DefaultTimeout is how long a gate may be held when its holder states no timeout.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, client machinev1connect.GateServiceClient, name, taskID string, c Command) (int, error)
Run takes the gate name from the server, for the task taskID when not empty, runs the command once it holds the gate, and gives the gate back when the command ends, fails or is interrupted. It returns the command's exit code. When the caller is killed, its connection ends, and the server gives the gate back.
Types ¶
type Command ¶
type Command struct {
Args []string
Dir string
Stdin io.Reader
Stdout, Stderr, Notice io.Writer // Notice gets what djinn says: why it waits, a gate lost
// Costs, when not nil, records what the command cost once it ended by itself: CPU time, peak memory, duration.
Costs machinev1connect.CommandServiceClient
}
Command is a command to run under a gate, with its standard streams.
type Costs ¶
type Costs interface {
Peak(ctx context.Context, taskID, dir, command string) uint64
Ask(ctx context.Context, gate, taskID, dir, command string)
}
Costs gives the highest peak memory a command was measured at, in its project: the task's, else the one holding dir; 0 when never measured. Ask counts a run of the command asked under the gate, whether it then runs to its end or not. machine.Peaks is one.
type Gates ¶
type Gates struct {
// contains filtered or unexported fields
}
Gates grants the gates. Its zero value is not usable: New makes one.
func New ¶
New returns the gates of machine m (nil: never under pressure, its memory unknown), the commands' measured costs being costs (nil: none measured), the holders' tasks being tasks (nil: none known).
func (*Gates) AddInterval ¶ added in v0.1.1
func (g *Gates) AddInterval(iv *machinev1.GateInterval)
AddInterval records a gate interval into history (used in tests).
func (*Gates) Freed ¶
func (g *Gates) Freed(f func())
Freed calls f each time a gate is given or taken back: a slot may have freed. djinn up wakes the scheduler.
func (*Gates) IfritWaits ¶ added in v0.2.0
IfritWaits names, by the task of each lit ifrit, who waits for a gate it holds, the first come first: "W15 (Its title): go tool task e2e, for stack". The lead's brief says it, to offer the developer to end the ifrit.
func (*Gates) Intervals ¶ added in v0.1.1
func (g *Gates) Intervals(cutoff time.Time) []*machinev1.GateInterval
Intervals returns recent gate intervals (past and currently held) since cutoff.
func (*Gates) Measure ¶
Measure reads, every interval, what each holder whose process is known uses, with read: djinn up gives machine.ReadWorker, where the system lets it measure (machine.NotMeasured).
func (*Gates) Outside ¶
Outside counts the gates held outside any running worker, by a person's terminal, a lead, a script or Djinn's merges and pushes, and of them the merges' and pushes' (Request.First): each takes a worker's slot, so no new worker starts on it while it is held. A worker's gate is in the worker's own slot.
func (*Gates) ProjectResolver ¶ added in v0.1.1
ProjectResolver sets the function that resolves a task and directory to a project name.
func (*Gates) Take ¶
Take waits until the gate is granted, and returns it held. waiting is called each time the reason to wait changes. Take fails when ctx ends first.
type Hold ¶
type Hold struct {
// contains filtered or unexported fields
}
Hold is a gate held.
func (*Hold) Done ¶
func (h *Hold) Done() <-chan struct{}
Done is closed once the gate is no longer held: given back, or taken back (TakenBack says why).
type Machine ¶
Machine is what the gates need from the machine: its pressure, its memory, and the policy that judges them. The monitor is one.
type Read ¶
Read reads what the process pid uses, with every process it started: machine.ReadWorker.
type Request ¶
type Request struct {
Name string
// TaskID, when not empty, is the task the gate is taken for: its events say when it waits, takes and gives the
// gate back.
TaskID string
// What says what the holder runs, in the folder Dir: a command measured in its project waits until the machine
// has the memory it peaked at.
What, Dir string
// PID is the holder's process, 0 when unknown: it is measured while it holds the gate, and the gate goes back
// once it ends.
PID int
// Timeout is how long the gate may be held: Djinn takes it back after that. 0: DefaultTimeout, but none for a lit
// ifrit, which holds its gates until it goes out or ends.
Timeout time.Duration
// First tells that Djinn takes the gate to merge a task's work into its branch (its wish's or its azima's), to
// settle such a merge, or to check a push: it blocks what comes after the task, so it goes before every other
// request, the first come first, and never waits for one that came after it (Q26).
First bool
}
Request is what a holder asks a gate for.
type State ¶
type State struct {
Name, Holder, HolderTaskID string
Since, Until time.Time // Until: when it is taken back at the latest; zero when not known
Waiting []string
WaitingTaskIDs []string // the tasks of the waiters, in the same order; a waiter outside any task left out
TakesSlot bool // held outside a running worker
Ifrit bool // held by a lit ifrit, until it goes out or ends
Use *planv1.Resources // what the holder's process uses; nil when not read
}
State is a gate held or waited for.
type Tasks ¶
type Tasks interface {
Describe(ctx context.Context, taskID string) (string, error)
Ranks(ctx context.Context, taskIDs []string) map[string]int
// Places gives the position of each task's azima among the azimas of its wish (Task.rank), from 0; a task part of
// no azima, or unknown, is not in the map.
Places(ctx context.Context, taskIDs []string) map[string]int
Note(taskID string, ev harness.Event)
Works(taskID string) bool
// Ifrit tells whether the task is an ifrit lit now, and when it goes out unless the developer comes back (zero:
// not known yet); once it no longer is, why says why: "went out: …", "ended". A task that is no ifrit is not lit,
// and has no why. It must not call the gates back.
Ifrit(ctx context.Context, taskID string) (lit bool, out time.Time, why string)
}
Tasks is what the gates need from the tasks: to name a holder, to rank waiters by their wish and their azima, to tell a task's events, whether a task's worker runs, which holds its gates in its own slot, and whether a task is a lit ifrit, which holds its gates until it goes out or ends. The harness is one.