bot

package
v0.0.0-...-f4b31ea Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package bot wraps managing Swarming bots.

Index

Constants

View Source
const GraceInterval = 3 * time.Minute

GraceInterval is the amount of time to provide for bots to terminate gracefully.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot interface {
	// Wait waits for the bot process to exit.  The return value
	// on subsequent calls is undefined.
	Wait() error
	// Drain signals for the bot to drain.  Note that this requires
	// support from the bot script.  This should be handled by Swarming
	// bots by waiting for the currently running task to finish before
	// exiting.
	Drain() error
	// TerminateOrKill terminates the bot with SIGTERM, then force kills it
	// after a grace period.
	// Swarming bots handle SIGTERM by aborting the currently running task and
	// exiting, but it can be hours long.
	// It relies on Wait() to be called to notify if the bot process has been
	// terminated.
	TerminateOrKill() error
}

Bot is the interface for interacting with a started Swarming bot. Wait must be called to ensure the process is waited for.

type Cgroup

type Cgroup cgroups.Cgroup

Cgroup is an alias of cgroups.Cgroup, which cannot be built on neither Windows or Mac.

type Config

type Config struct {
	BotID string
	// WorkDirectory is the Swarming bot's work directory.
	// The caller should create this.
	// The parent directory should be writable to allow creation
	// of the drain file.
	WorkDirectory string
	// The Linux compute resources (CPU, RAM, I/O, etc.) assigned to this bot.
	Resources     *specs.LinuxResources
	PythonVersion string
}

Config is the configuration needed for starting a generic Swarming bot.

type DroneStarter

type DroneStarter struct {
	// WorkingDir is used for Swarming bot working dirs.  It is
	// the caller's responsibility to create this.
	WorkingDir string
	// StartBotFunc is used to start Swarming bots.
	StartBotFunc func(Config) (Bot, error)
	// BotConfigFunc is used to make a bot config.
	BotConfigFunc func(botID string, workDir string) Config
	// LogFunc is used for logging messages.
	LogFunc func(string, ...any)
}

A DroneStarter starts a bot for a drone. It handles setting up the working dir, etc. Low level process execution is handled by a separate StartBotFunc for testing and abstraction. All fields must be set. In particular, the function fields must not be nil.

func (DroneStarter) Start

func (s DroneStarter) Start(botID string) (Bot, error)

Start starts a Swarming bot. The returned Bot object can be used to interact with the bot.

type FakeBot

type FakeBot struct {

	// DrainFunc, if set, is called when the bot is drained.  The
	// default behavior is Stop.
	DrainFunc func(*FakeBot) error
	// TerminateFunc, if set, is called when the bot is terminated.
	// The default behavior is Stop.
	TerminateFunc func(*FakeBot) error
	// contains filtered or unexported fields
}

FakeBot is a fake implementation of Bot for tests.

func NewFakeBot

func NewFakeBot() *FakeBot

NewFakeBot returns a new FakeBot.

func (*FakeBot) Drain

func (b *FakeBot) Drain() error

Drain implements Bot.

func (*FakeBot) Stop

func (b *FakeBot) Stop()

Stop stops the "bot process".

func (*FakeBot) StopWith

func (b *FakeBot) StopWith(err error)

StopWith stops the "bot process" with an error to be returned from Wait.

func (*FakeBot) TerminateOrKill

func (b *FakeBot) TerminateOrKill() error

TerminateOrKill implements Bot.

func (*FakeBot) Wait

func (b *FakeBot) Wait() error

Wait implements Bot.

type Starter

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

Starter has a Start method for starting Swarming bots.

func NewStarter

func NewStarter(c *http.Client, swarmingURL string) Starter

NewStarter returns a new Starter. swarmingURL is the URL of the Swarming instance. Should be a full URL without the path, e.g. https://host.example.com

func (Starter) Start

func (s Starter) Start(c Config) (b Bot, err error)

Start starts a Swarming bot. The returned Bot object can be used to interact with the bot.

Jump to

Keyboard shortcuts

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