Documentation
¶
Overview ¶
Package mailbox decides which connected copy of an agent gets the next task.
Each agent address can have several tunnel sessions (copies of the agent on a laptop, a server, a GPU box), and each session says how many tasks it runs at once. Together they form a worker pool. Acquire hands out a slot on the least busy session and blocks while every session is full or none is connected, which is how a task waits for an offline agent.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mailbox ¶
type Mailbox struct {
// OnChange, if set, is called (without the lock held) after an address's stats change.
OnChange func(handle string, stats Stats)
// contains filtered or unexported fields
}
Mailbox tracks the sessions of every address.
func (*Mailbox) Acquire ¶
func (m *Mailbox) Acquire(ctx context.Context, handle string, onWait func()) (s Session, release func(), err error)
Acquire waits for a free slot on one of handle's sessions. onWait, if not nil, is called once when Acquire has to wait. release must be called when the task is done with the session.
type Session ¶
type Session interface {
// ID identifies the session.
ID() string
// Capacity is how many tasks the session runs at once.
Capacity() int
// Transport sends HTTP requests to the agent through the session.
Transport() http.RoundTripper
// Done is closed when the session ends.
Done() <-chan struct{}
}
Session is one connected copy of an agent.