supervisor

package
v0.0.0-...-9dc60ae Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

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