Documentation
¶
Overview ¶
Package queue holds the Redis-backed run queue, the per-run control channel (cancel) and the per-run steer list.
Index ¶
- Constants
- Variables
- func SteerMessages(threadID, runID string, steers []Steer) []*store.Message
- type Bus
- type Memory
- func (q *Memory) Ack(context.Context, string) error
- func (q *Memory) AckSteers(_ context.Context, runID string, n int) error
- func (q *Memory) CloseSteers(_ context.Context, runID string) ([]Steer, error)
- func (q *Memory) DrainSteers(_ context.Context, runID string) ([]Steer, error)
- func (q *Memory) Enqueue(_ context.Context, runID string) error
- func (q *Memory) EnsureGroup(context.Context) error
- func (q *Memory) FinalizeSteers(_ context.Context, runID string) ([]Steer, error)
- func (q *Memory) PruneConsumers(context.Context, string, time.Duration) (int, error)
- func (q *Memory) PublishCancel(_ context.Context, runID string) error
- func (q *Memory) PushSteer(_ context.Context, runID string, s Steer) error
- func (q *Memory) Read(ctx context.Context, _ string, count int, block time.Duration) ([]Message, error)
- func (q *Memory) Reclaim(context.Context, string, time.Duration) ([]Message, error)
- func (q *Memory) ReopenSteers(_ context.Context, runID string) error
- func (q *Memory) SteerRuns(context.Context) ([]string, error)
- func (q *Memory) SubscribeCancel(_ context.Context, runID string, fn func()) (func(), error)
- type Message
- type MessageAppender
- type Queue
- type Steer
Constants ¶
const ( // Stream is the run queue. Stream = "work:runs" // Group is the consumer group of runtimes. Group = "runtime" // MaxSteers is the cap of pending steer messages per run. MaxSteers = 20 )
Variables ¶
var ( // ErrTooManySteers is returned when MaxSteers are already pending. ErrTooManySteers = errors.New("too many pending steer messages") // ErrSteersClosed is returned once the run stopped accepting steers (final step or finished). ErrSteersClosed = errors.New("the run no longer accepts messages") )
Functions ¶
Types ¶
type Bus ¶
type Bus interface {
PublishCancel(ctx context.Context, runID string) error
// SubscribeCancel calls fn when a cancel is published; the returned func unsubscribes.
SubscribeCancel(ctx context.Context, runID string, fn func()) (func(), error)
// PushSteer fails with ErrSteersClosed after FinalizeSteers.
PushSteer(ctx context.Context, runID string, s Steer) error
DrainSteers(ctx context.Context, runID string) ([]Steer, error)
// FinalizeSteers atomically stops accepting steers and returns the pending ones.
FinalizeSteers(ctx context.Context, runID string) ([]Steer, error)
// ReopenSteers accepts steers again (the run continues after all).
ReopenSteers(ctx context.Context, runID string) error
// CloseSteers stops accepting steers and returns the pending ones without
// removing them: AckSteers removes them once they are stored elsewhere.
CloseSteers(ctx context.Context, runID string) ([]Steer, error)
// AckSteers removes the first n pending steers (stored by the caller).
AckSteers(ctx context.Context, runID string, n int) error
// SteerRuns lists the runs that may still hold pending steers (the
// sweeper stores those of finished runs).
SteerRuns(ctx context.Context) ([]string, error)
}
Bus carries per-run control signals and steers.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is an in-process run queue and control bus: it implements Queue, the runtime's RunQueue and Bus without Redis, for a host that runs the agent in its own process (TUI, desktop app, tests).
func (*Memory) CloseSteers ¶
func (*Memory) DrainSteers ¶
func (*Memory) EnsureGroup ¶
EnsureGroup is a no-op.
func (*Memory) FinalizeSteers ¶
func (*Memory) PruneConsumers ¶
func (*Memory) PublishCancel ¶
func (*Memory) Read ¶
func (q *Memory) Read(ctx context.Context, _ string, count int, block time.Duration) ([]Message, error)
Read waits up to block for queued runs and hands out at most count of them. Delivery is at most once: a process that dies loses its queue anyway.
type MessageAppender ¶
type MessageAppender interface {
AppendMessages(ctx context.Context, msgs ...*store.Message) error
}
MessageAppender stores thread messages (store.Store).
type Steer ¶
type Steer struct {
ID string `json:"id"`
Text string `json:"text"`
// Author is who sent the steer, with AuthorKind and OnBehalfOf as on store.Message.
Author string `json:"author,omitempty"`
AuthorKind string `json:"authorKind,omitempty"`
OnBehalfOf string `json:"onBehalfOf,omitempty"`
}
Steer is a user message injected into a running run.
func KeepSteers ¶
func KeepSteers(ctx context.Context, bus Bus, st MessageAppender, threadID, runID string, deadline time.Time) ([]Steer, error)
KeepSteers closes a run's steer list and stores its pending steers in the thread (delivered=false), retrying transient Redis/Postgres errors until deadline. It returns the steers that are stored (only those may be announced as kept); on error the steers stay pending in Redis, listed by SteerRuns, so the sweeper stores them later: an accepted steer is never lost.