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, the first wish of the rank first. A holder keeps its gate until it gives it back, its connection ends, its process ends or its timeout passes. 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) Freed(f func())
- func (g *Gates) Held(taskID string) []string
- func (g *Gates) List() []State
- func (g *Gates) Measure(every time.Duration, read Read)
- func (g *Gates) Outside() int
- func (g *Gates) Take(ctx context.Context, r Request, waiting func(why string)) (*Hold, error)
- 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 ¶
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. 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) 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) 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 or a script: 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.
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.
Timeout time.Duration
}
Request is what a holder asks a gate for.
type State ¶
type State struct {
Name, Holder, HolderTaskID string
Since, Until time.Time
Waiting []string
TakesSlot bool // held outside a running worker
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
Note(taskID string, ev harness.Event)
Works(taskID string) bool
}
Tasks is what the gates need from the tasks: to name a holder, to rank waiters by their wish, to tell a task's events, and whether a task's worker runs, which holds its gates in its own slot. The harness is one.