head

package
v0.0.0-...-f9802cd Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 18 Imported by: 0

README

head

import "github.com/cognusion/prochydra/head"

Overview

Index

Package files

common.go head.go

func ReadLogger

func ReadLogger(reader io.Reader, writer *log.Logger, errorChan chan<- error)

ReadLogger continuously reads from an io.Reader, and blurts to the specified log.Logger

type Head

type Head struct {
    // ID is a generated ID based on the sequence
    ID string
    // RestartDelay specified the duration to wait between restarts
    RestartDelay time.Duration
    // MaxPSS specifies the maximum PSS size a process may have before being killed
    MaxPSS int64
    // DebugOut is a logger for debug information
    DebugOut *log.Logger
    // ErrOut is a logger for errors, generally, emitted by a Head
    ErrOut *log.Logger
    // StdErr is a logger for StdErr coming from a process
    StdErr *log.Logger
    // StdOut is a logger for StdOut coming from a process
    StdOut *log.Logger
    // UID is the uid to run as (leave unset for current user)
    UID uint32
    // GID is the gid to run as (leave unset for current group)
    GID uint32
    // Seq is a pointer to an initialized sequencer
    Seq *sequence.Seq
    // Values is a map for implementors to store key-value pairs. Never consulted by the Head library.
    Values sync.Map
    // Timeout is a duration after which the process running is stopped, subject to  Autorestart
    Timeout time.Duration
    // StdInNoNL is a boolean to describe if a NewLine should *not* be appended to lines written to StdIn.
    // This is advisory-only, and respected by hydra but not necessarily others.
    StdInNoNL bool
    // StdInShellEscapeInput is a boolean to describe if strings send to StdIn should be shell-escaped.
    // This is advisory-only, and respected by hydra but not necessarily others.
    StdInShellEscapeInput bool
    // contains filtered or unexported fields
}

Head is a struct to contain a process a run. You can Run() the same Head multiple times if you need clones.

func BashDashC
func BashDashC(command string, errorChan chan error) *Head

BashDashC creates a head that handles the command in its entirety running as a "bash -c command"

func New
func New(command string, args []string, errorChan chan error) *Head

New returns a Head struct, ready to Run() the command with the arguments specified. It would be wise to ensure the errorChan reader is ready before calling Run() to prevent goro plaque.

func (*Head) Autorestart
func (r *Head) Autorestart(doit bool)

Autorestart sets whether or not we will automatically restart Heads that "complete"

func (*Head) Clone
func (r *Head) Clone() *Head

Clone returns a new Head intialized the same as the current

func (*Head) Errors
func (r *Head) Errors() uint64

Errors returns the current number of errors sent to the error chan

func (*Head) Restarts
func (r *Head) Restarts() uint64

Restarts returns the current number of restarts for this Head instance

func (*Head) RestartsPerMinute
func (r *Head) RestartsPerMinute() uint64

RestartsPerMinute returns the number of restarts for this Head instance in the last minute

func (*Head) Run
func (r *Head) Run() string

Run executes a subprocess of the command and arguments specified, restarting it if applicable. The returned channel returns the name of the once it is running, or closes it without a value if it will not run.

func (*Head) SetChildEnv
func (r *Head) SetChildEnv(env []string)

SetChildEnv takes a list of key=value strings to pass to all spawned processes

func (*Head) SetMgInterval
func (r *Head) SetMgInterval(interval time.Duration)

SetMgInterval sets the interval at which the memory usage is checked, for use with MaxPSS. Default 30s.

func (*Head) Stop
func (r *Head) Stop()

Stop signals all of the running processes to die. May generate error output thereafter.

func (*Head) String
func (r *Head) String() string

String returns the original command and arguments in a line

func (*Head) Wait
func (r *Head) Wait()

Wait blocks until the Run() process has completed

func (*Head) Write
func (r *Head) Write(p []byte) (n int, err error)

Write implements io.Writer to ease writing to StdIn

type Sbuffer

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

Sbuffer is a goro-safe bytes.Buffer

func (*Sbuffer) String
func (s *Sbuffer) String() string

String returns the contents of the unread portion of the buffer as a string.

func (*Sbuffer) Write
func (s *Sbuffer) Write(p []byte) (n int, err error)

Write appends the contents of p to the buffer, growing the buffer as needed. It returns the number of bytes written or an error.


Generated by godoc2md

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadLogger

func ReadLogger(reader io.Reader, writer *log.Logger, errorChan chan<- error)

ReadLogger continuously reads from an io.Reader, and blurts to the specified log.Logger

Types

type Head struct {
	// ID is a generated ID based on the sequence
	ID string
	// RestartDelay specified the duration to wait between restarts
	RestartDelay time.Duration
	// MaxPSS specifies the maximum PSS size a process may have before being killed
	MaxPSS int64
	// DebugOut is a logger for debug information
	DebugOut *log.Logger
	// ErrOut is a logger for errors, generally, emitted by a Head
	ErrOut *log.Logger
	// StdErr is a logger for StdErr coming from a process
	StdErr *log.Logger
	// StdOut is a logger for StdOut coming from a process
	StdOut *log.Logger
	// UID is the uid to run as (leave unset for current user)
	UID uint32
	// GID is the gid to run as (leave unset for current group)
	GID uint32
	// Seq is a pointer to an initialized sequencer
	Seq *sequence.Seq
	// Values is a map for implementors to store key-value pairs. Never consulted by the Head library.
	Values sync.Map
	// Timeout is a duration after which the process running is stopped, subject to  Autorestart
	Timeout time.Duration
	// StdInNoNL is a boolean to describe if a NewLine should *not* be appended to lines written to StdIn.
	// This is advisory-only, and respected by hydra but not necessarily others.
	StdInNoNL bool
	// StdInShellEscapeInput is a boolean to describe if strings send to StdIn should be shell-escaped.
	// This is advisory-only, and respected by hydra but not necessarily others.
	StdInShellEscapeInput bool
	// contains filtered or unexported fields
}

Head is a struct to contain a process a run. You can Run() the same Head multiple times if you need clones.

func BashDashC

func BashDashC(command string, errorChan chan error) *Head

BashDashC creates a head that handles the command in its entirety running as a "bash -c command"

func New

func New(command string, args []string, errorChan chan error) *Head

New returns a Head struct, ready to Run() the command with the arguments specified. It would be wise to ensure the errorChan reader is ready before calling Run() to prevent goro plaque.

func (*Head) Autorestart

func (r *Head) Autorestart(doit bool)

Autorestart sets whether or not we will automatically restart Heads that "complete"

func (*Head) Clone

func (r *Head) Clone() *Head

Clone returns a new Head intialized the same as the current

func (*Head) Errors

func (r *Head) Errors() uint64

Errors returns the current number of errors sent to the error chan

func (*Head) Restarts

func (r *Head) Restarts() uint64

Restarts returns the current number of restarts for this Head instance

func (*Head) RestartsPerMinute

func (r *Head) RestartsPerMinute() uint64

RestartsPerMinute returns the number of restarts for this Head instance in the last minute

func (*Head) Run

func (r *Head) Run() string

Run executes a subprocess of the command and arguments specified, restarting it if applicable. The returned channel returns the name of the once it is running, or closes it without a value if it will not run.

func (*Head) SetChildEnv

func (r *Head) SetChildEnv(env []string)

SetChildEnv takes a list of key=value strings to pass to all spawned processes

func (*Head) SetMgInterval

func (r *Head) SetMgInterval(interval time.Duration)

SetMgInterval sets the interval at which the memory usage is checked, for use with MaxPSS. Default 30s.

func (*Head) Stop

func (r *Head) Stop()

Stop signals all of the running processes to die. May generate error output thereafter.

func (*Head) String

func (r *Head) String() string

String returns the original command and arguments in a line

func (*Head) Wait

func (r *Head) Wait()

Wait blocks until the Run() process has completed

func (*Head) Write

func (r *Head) Write(p []byte) (n int, err error)

Write implements io.Writer to ease writing to StdIn

type Sbuffer

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

Sbuffer is a goro-safe bytes.Buffer

func (*Sbuffer) String

func (s *Sbuffer) String() string

String returns the contents of the unread portion of the buffer as a string.

func (*Sbuffer) Write

func (s *Sbuffer) Write(p []byte) (n int, err error)

Write appends the contents of p to the buffer, growing the buffer as needed. It returns the number of bytes written or an error.

Jump to

Keyboard shortcuts

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