supervisor

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: Apache-2.0 Imports: 14 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

This package contains a simple supervisor for goroutine workers.

Index

Constants

View Source
const DefaultSupervisorTimeout = time.Second * 15

Timeout when waiting for workers to finish.

View Source
const ServerPollInterval = 10 * time.Millisecond

Poll interval when checking whether the server is ready.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandWorker

type CommandWorker struct {
	Name    string
	Command string
	Args    []string
	Env     []string
}

This worker is responsible for a shell command that runs endlessly.

func (CommandWorker) Start

func (w CommandWorker) Start(ctx context.Context, ready chan<- struct{}) error

func (CommandWorker) String

func (w CommandWorker) String() string

type HttpWorker

type HttpWorker struct {
	Address string
	Handler http.Handler
}

The HTTP worker starts and manage an HTTP server.

func (HttpWorker) Start

func (w HttpWorker) Start(ctx context.Context, ready chan<- struct{}) error

func (HttpWorker) String

func (w HttpWorker) String() string

type ServerWorker

type ServerWorker struct {
	CommandWorker
	Port int
}

This worker is responsible for a shell command that runs endlessly. The worker polls the given port to know when it is ready.

func (ServerWorker) Start

func (w ServerWorker) Start(ctx context.Context, ready chan<- struct{}) error

type SupervisorWorker

type SupervisorWorker struct {
	Name    string
	Workers []Worker
	Timeout time.Duration
}

Start the workers in order, waiting for each one to be ready before starting the next one. When a worker exits, send a cancel signal to all of them and wait for them to finish.

func (SupervisorWorker) Start

func (w SupervisorWorker) Start(ctx context.Context, ready chan<- struct{}) error

func (SupervisorWorker) String

func (w SupervisorWorker) String() string

type Worker

type Worker interface {
	fmt.Stringer

	// Start the worker.
	// The worker should send a message to the ready channel when it is ready.
	Start(ctx context.Context, ready chan<- struct{}) error
}

Worker managed by the supervisor.

Jump to

Keyboard shortcuts

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