listener

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 8 Imported by: 4

Documentation

Overview

Package listener provides a listener for GitHub Actions runner scale set messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	GetMessage(ctx context.Context, lastMessageID, maxCapacity int) (*scaleset.RunnerScaleSetMessage, error)
	DeleteMessage(ctx context.Context, messageID int) error
	Session() scaleset.RunnerScaleSetSession
}

Client defines the interface for communicating with the scaleset API. In most cases, it should be scaleset.Client from the scaleset package. This interface is defined to allow for easier testing and mocking, as well as allowing wrappers around the scaleset client if needed.

type Config

type Config struct {
	// ScaleSetID is the ID of the runner scale set to listen to.
	ScaleSetID int
	// MaxRunners is the capacity of runners that can be handled at once.
	MaxRunners int
	// Logger is the logger to use for logging. Default is a no-op logger.
	Logger *slog.Logger
}

Config holds the configuration for the Listener.

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if the configuration is invalid.

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener listens for messages from the scaleset service and handles them. It automatically handles session creation/deletion/refreshing and message polling and acking.

func New

func New(client Client, config Config, options ...Option) (*Listener, error)

New creates a new Listener with the given configuration.

func (*Listener) Run

func (l *Listener) Run(ctx context.Context, scaler Scaler) error

Run starts the listener and processes messages using the provided scaler.

func (*Listener) SetMaxRunners

func (l *Listener) SetMaxRunners(count int)

SetMaxRunners sets the capacity of the scaleset. It is concurrently safe to update the max runners during listener.Run.

type MetricsRecorder added in v0.2.0

type MetricsRecorder interface {
	RecordStatistics(statistics *scaleset.RunnerScaleSetStatistic)
	RecordJobStarted(msg *scaleset.JobStarted)
	RecordJobCompleted(msg *scaleset.JobCompleted)
	RecordDesiredRunners(count int)
}

MetricsRecorder defines the hook methods that will be called by the listener at various points in the message handling process. This allows for custom metrics to be collected without coupling the listener to a specific metrics implementation. The methods in this interface will be called with relevant information about the message handling process, such as the number of jobs started/completed, the desired runner count, and any errors that occur. Implementers can use this information to track the performance and behavior of the listener and the scaleset service.

type Option

type Option func(*Listener)

func WithMetricsRecorder added in v0.2.0

func WithMetricsRecorder(recorder MetricsRecorder) Option

WithMetricsRecorder sets the MetricsRecorder for the listener. If not set, a no-op recorder will be used. If the nil is passed, the MetricsRecorder will not be updated and the existing one will be used (which is a no-op by default).

type Scaler

type Scaler interface {
	HandleJobStarted(ctx context.Context, jobInfo *scaleset.JobStarted) error
	HandleJobCompleted(ctx context.Context, jobInfo *scaleset.JobCompleted) error
	HandleDesiredRunnerCount(ctx context.Context, count int) (int, error)
}

Scaler defines the interface for handling scale set messages.

Jump to

Keyboard shortcuts

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