agent

package
v0.0.0-...-c2cc3df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnabledCacheTTL         = 1 * time.Minute
	RoomAgentTopic          = "room"
	PublisherAgentTopic     = "publisher"
	DefaultHandlerNamespace = ""

	CheckEnabledTimeout = 5 * time.Second
)
View Source
const (
	RegisterTimeout  = 10 * time.Second
	AssignJobTimeout = 10 * time.Second
)
View Source
const CurrentProtocol = 1

Variables

View Source
var (
	ErrUnimplementedWrorkerSignal = errors.New("unimplemented worker signal")
	ErrUnknownWorkerSignal        = errors.New("unknown worker signal")
	ErrUnknownJobType             = errors.New("unknown job type")
	ErrJobNotFound                = psrpc.NewErrorf(psrpc.NotFound, "no running job for given jobID")
	ErrWorkerClosed               = errors.New("worker closed")
	ErrWorkerNotAvailable         = errors.New("worker not available")
	ErrAvailabilityTimeout        = errors.New("agent worker availability timeout")
	ErrDuplicateJobAssignment     = errors.New("duplicate job assignment")
)

Functions

func DispatchWorkerSignal

func DispatchWorkerSignal(req *livekit.WorkerMessage, h WorkerSignalHandler) error

func GetAgentTopic

func GetAgentTopic(agentName, namespace string) string

func JobStatusIsEnded

func JobStatusIsEnded(s livekit.JobStatus) bool

Types

type Client

type Client interface {
	// LaunchJob starts a room or participant job on an agent.
	// it will launch a job once for each worker in each namespace
	LaunchJob(ctx context.Context, desc *JobRequest) *serverutils.IncrementalDispatcher[*livekit.Job]
	TerminateJob(ctx context.Context, jobID string, reason rpc.JobTerminateReason) (*livekit.JobState, error)
	Stop() error
}

func NewAgentClient

func NewAgentClient(bus psrpc.MessageBus) (Client, error)

type JobRequest

type JobRequest struct {
	DispatchId string
	JobType    livekit.JobType
	Room       *livekit.Room
	// only set for participant jobs
	Participant *livekit.ParticipantInfo
	Metadata    string
	AgentName   string
}

type SignalConn

type SignalConn interface {
	WriteServerMessage(msg *livekit.ServerMessage) (int, error)
	ReadWorkerMessage() (*livekit.WorkerMessage, int, error)
	SetReadDeadline(time.Time) error
	Close() error
}

type UnimplementedWorkerSignalHandler

type UnimplementedWorkerSignalHandler struct{}

func (UnimplementedWorkerSignalHandler) HandleAvailability

func (UnimplementedWorkerSignalHandler) HandleMigrateJob

func (UnimplementedWorkerSignalHandler) HandlePing

func (UnimplementedWorkerSignalHandler) HandleRegister

func (UnimplementedWorkerSignalHandler) HandleSimulateJob

func (UnimplementedWorkerSignalHandler) HandleUpdateJob

func (UnimplementedWorkerSignalHandler) HandleUpdateWorker

type Worker

type Worker struct {
	WorkerPingHandler
	WorkerRegistration
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(
	registration WorkerRegistration,
	apiKey string,
	apiSecret string,
	conn SignalConn,
	logger logger.Logger,
) *Worker

func (*Worker) AssignJob

func (w *Worker) AssignJob(ctx context.Context, job *livekit.Job) (*livekit.JobState, error)

func (*Worker) Close

func (w *Worker) Close()

func (*Worker) GetJobState

func (w *Worker) GetJobState(jobID livekit.JobID) (*livekit.JobState, error)

func (*Worker) HandleAvailability

func (w *Worker) HandleAvailability(res *livekit.AvailabilityResponse) error

func (*Worker) HandleMigrateJob

func (w *Worker) HandleMigrateJob(req *livekit.MigrateJobRequest) error

func (*Worker) HandleSimulateJob

func (w *Worker) HandleSimulateJob(simulate *livekit.SimulateJobRequest) error

func (*Worker) HandleUpdateJob

func (w *Worker) HandleUpdateJob(update *livekit.UpdateJobStatus) error

func (*Worker) HandleUpdateWorker

func (w *Worker) HandleUpdateWorker(update *livekit.UpdateWorkerStatus) error

func (*Worker) IsClosed

func (w *Worker) IsClosed() bool

func (*Worker) Load

func (w *Worker) Load() float32

func (*Worker) Logger

func (w *Worker) Logger() logger.Logger

func (*Worker) RunningJobCount

func (w *Worker) RunningJobCount() int

func (*Worker) RunningJobs

func (w *Worker) RunningJobs() map[livekit.JobID]*livekit.Job

func (*Worker) Status

func (w *Worker) Status() livekit.WorkerStatus

func (*Worker) TerminateJob

func (w *Worker) TerminateJob(jobID livekit.JobID, reason rpc.JobTerminateReason) (*livekit.JobState, error)

func (*Worker) UpdateJobStatus

func (w *Worker) UpdateJobStatus(update *livekit.UpdateJobStatus) (*livekit.JobState, error)

func (*Worker) UpdateMetadata

func (w *Worker) UpdateMetadata(metadata string)

type WorkerPingHandler

type WorkerPingHandler struct {
	UnimplementedWorkerSignalHandler
	// contains filtered or unexported fields
}

func (WorkerPingHandler) HandlePing

func (h WorkerPingHandler) HandlePing(ping *livekit.WorkerPing) error

type WorkerProtocolVersion

type WorkerProtocolVersion int

type WorkerRegisterer

type WorkerRegisterer struct {
	WorkerPingHandler
	// contains filtered or unexported fields
}

func NewWorkerRegisterer

func NewWorkerRegisterer(conn SignalConn, serverInfo *livekit.ServerInfo, protocol WorkerProtocolVersion) *WorkerRegisterer

func (*WorkerRegisterer) Deadline

func (h *WorkerRegisterer) Deadline() time.Time

func (*WorkerRegisterer) HandleRegister

func (h *WorkerRegisterer) HandleRegister(req *livekit.RegisterWorkerRequest) error

func (*WorkerRegisterer) Registered

func (h *WorkerRegisterer) Registered() bool

func (*WorkerRegisterer) Registration

func (h *WorkerRegisterer) Registration() WorkerRegistration

type WorkerRegistration

type WorkerRegistration struct {
	Protocol    WorkerProtocolVersion
	ID          string
	Version     string
	AgentName   string
	Namespace   string
	JobType     livekit.JobType
	Permissions *livekit.ParticipantPermission
}

type WorkerSignalHandler

type WorkerSignalHandler interface {
	HandleRegister(*livekit.RegisterWorkerRequest) error
	HandleAvailability(*livekit.AvailabilityResponse) error
	HandleUpdateJob(*livekit.UpdateJobStatus) error
	HandleSimulateJob(*livekit.SimulateJobRequest) error
	HandlePing(*livekit.WorkerPing) error
	HandleUpdateWorker(*livekit.UpdateWorkerStatus) error
	HandleMigrateJob(*livekit.MigrateJobRequest) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL