server

package module
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: MIT Imports: 18 Imported by: 1

README

Documentation

Index

Constants

View Source
const (
	// PluginName for the server
	PluginName string = "server"

	// RPCPluginName is the name of the RPC plugin, should be in sync with rpc/config.go
	RPCPluginName string = "rpc"

	// RrRelay env variable key (internal)
	RrRelay string = "RR_RELAY"

	// RrRPC env variable key (internal) if the RPC presents
	RrRPC string = "RR_RPC"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// OnInit configuration
	OnInit *OnInitConfig `mapstructure:"on_init"`

	// Command to run as application.
	Command string `mapstructure:"command"`

	// User to run application under.
	User string `mapstructure:"user"`

	// Group to run application under.
	Group string `mapstructure:"group"`

	// Env represents application environment.
	Env map[string]string `mapstructure:"env"`

	// Relay defines connection method and factory to be used to connect to workers:
	// "pipes", "tcp://:6001", "unix://rr.sock"
	// This config section must not change on re-configuration.
	Relay string `mapstructure:"relay"`

	// RelayTimeout defines for how long socket factory will be waiting for worker connection. This config section
	// must not change on re-configuration. Defaults to 60s.
	RelayTimeout time.Duration `mapstructure:"relay_timeout"`
}

Config All config (.rr.yaml) For other section use pointer to distinguish between `empty` and `not present`

func (*Config) InitDefaults

func (cfg *Config) InitDefaults() error

InitDefaults for the server config

type Configurer

type Configurer interface {
	// UnmarshalKey takes a single key and unmarshal it into a Struct.
	UnmarshalKey(name string, out any) error

	// Has checks if config section exists.
	Has(name string) bool
}

type OnInitConfig

type OnInitConfig struct {
	// Command which is started before worker starts
	Command string `mapstructure:"command"`

	// ExecTimeout is execute timeout for the command
	ExecTimeout time.Duration `mapstructure:"exec_timeout"`

	// Env represents application environment.
	Env map[string]string `mapstructure:"env"`
}

type Plugin

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

Plugin manages worker

func (*Plugin) CmdFactory

func (p *Plugin) CmdFactory(env map[string]string) func() *exec.Cmd

CmdFactory provides worker command factory associated with given context

func (*Plugin) GID

func (p *Plugin) GID() int

GID returns a group id (if specified by user)

func (*Plugin) Init

func (p *Plugin) Init(cfg Configurer, log *zap.Logger) error

Init application provider.

func (*Plugin) Name

func (p *Plugin) Name() string

Name contains service name.

func (*Plugin) NewPool

func (p *Plugin) NewPool(ctx context.Context, cfg *pool.Config, env map[string]string, _ *zap.Logger) (*staticPool.Pool, error)

NewPool issues new worker pool.

func (*Plugin) NewWorker

func (p *Plugin) NewWorker(ctx context.Context, env map[string]string) (*worker.Process, error)

NewWorker issues new standalone worker.

func (*Plugin) Serve

func (p *Plugin) Serve() chan error

Serve (Start) server plugin (just a mock here to satisfy interface)

func (*Plugin) Stop

func (p *Plugin) Stop() error

Stop used to close chosen in config factory

func (*Plugin) UID

func (p *Plugin) UID() int

UID returns a user id (if specified by user)

func (*Plugin) Write

func (p *Plugin) Write(data []byte) (int, error)

type Pool

type Pool interface {
	// GetConfig returns pool configuration.
	GetConfig() *pool.Config

	// Workers returns worker list associated with the pool.
	Workers() (workers []*worker.Process)

	// RemoveWorker removes worker from the pool.
	RemoveWorker(worker *worker.Process) error

	// Exec payload
	Exec(ctx context.Context, p *payload.Payload) (*payload.Payload, error)

	// Reset kill all workers inside the watcher and replaces with new
	Reset(ctx context.Context) error

	// Destroy all underlying stack (but let them to complete the task).
	Destroy(ctx context.Context)
}

Pool managed set of inner worker processes.

type RPCConfig

type RPCConfig struct {
	Listen string `mapstructure:"listen"`
}

RPCConfig should be in sync with rpc/config.go Used to set RPC address env

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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