services

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package services provides mechanisms to start multiple services in the background

Index

Constants

View Source
const (
	DefaultPollInterval = 100 * time.Millisecond
)
View Source
const DefaultServiceTimeout = 5 * time.Second

Variables

View Source
var (
	ServiceTimeoutError    = errors.New("timed out waiting for service to be ready")
	SupervisorTimeoutError = errors.New("timed out waiting for services to stop")
)

Functions

This section is empty.

Types

type CommandService added in v1.3.0

type CommandService struct {

	// Name that identifies the service.
	Name string

	// Port used to verify if the service is ready.
	HealthcheckPort int

	// Path to the service binary.
	Path string

	// Args to the service binary.
	Args []string

	// Environment variables.
	Env []string
}

CommandService encapsulates the execution of an executable via exec.Command. It assumes the executable accepts TCP connections at HealthcheckPort, which it uses to determine if it is ready or not.

func (CommandService) Start added in v1.3.0

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

func (CommandService) String added in v1.3.0

func (s CommandService) String() string

type HttpService added in v1.3.0

type HttpService struct {
	Name    string
	Address string
	Handler http.Handler
}

func (HttpService) Start added in v1.3.0

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

func (HttpService) String added in v1.3.0

func (s HttpService) String() string

type ServerManager added in v1.3.0

type ServerManager struct {
	// Name that identifies the service.
	Name string

	// Port used to verify if the service is ready.
	HealthcheckPort int

	// Path to the service binary.
	Path string

	// Args to the service binary.
	Args []string

	// Environment variables.
	Env []string
}

ServerManager is a variation of CommandService used to manually stop the orphaned cartesi-machines left after server-manager exits. For more information, check https://github.com/cartesi/server-manager/issues/18

func (ServerManager) Start added in v1.3.0

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

func (ServerManager) String added in v1.3.0

func (s ServerManager) String() string

type Service

type Service interface {
	fmt.Stringer

	// Starts a service and sends a message to the channel when ready
	Start(ctx context.Context, ready chan<- struct{}) error
}

type SupervisorService added in v1.3.0

type SupervisorService struct {
	// Name of the service
	Name string

	// Services to be managed
	Services []Service

	// The amount of time to wait for a service to be ready.
	// Default is 5 seconds
	ReadyTimeout time.Duration

	// The amount of time to wait for a service to exit after
	// its context is canceled. Default is 5 seconds
	StopTimeout time.Duration
}

SupervisorService is a simple implementation of a supervisor. It runs its services until the first returns a non-nil error.

func (SupervisorService) Start added in v1.3.0

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

func (SupervisorService) String added in v1.3.0

func (s SupervisorService) String() string

Directories

Path Synopsis
This file creates a dummy webserver with the sole pupose of being used as a binary to test the services.Service struct
This file creates a dummy webserver with the sole pupose of being used as a binary to test the services.Service struct

Jump to

Keyboard shortcuts

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