kelpos

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotInstance

type BotInstance struct {
	Bot   *model2.Bot
	State BotState
}

BotInstance is an instance of a given bot along with the metadata

type BotState

type BotState uint8
const (
	BotStateInitializing BotState = iota
	BotStateStopped
	BotStateRunning
	BotStateStopping
)

func InitState

func InitState() BotState

InitState is the first state of the bot

func (BotState) String

func (bs BotState) String() string

String impl

type KelpOS

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

KelpOS is a struct that manages all subprocesses started by this Kelp process

func GetKelpOS

func GetKelpOS() *KelpOS

GetKelpOS gets the singleton instance

func (*KelpOS) AdvanceBotState

func (kos *KelpOS) AdvanceBotState(botName string, expectedCurrentState BotState) error

AdvanceBotState advances the state of the given bot atomically, ensuring the bot is currently at the expected state

func (*KelpOS) Background

func (kos *KelpOS) Background(namespace string, cmd string) (*Process, error)

Background runs the provided bash command in the background and registers the command

func (*KelpOS) Blocking

func (kos *KelpOS) Blocking(namespace string, cmd string) ([]byte, error)

Blocking runs a bash command and blocks

func (*KelpOS) GetBot

func (kos *KelpOS) GetBot(botName string) (*BotInstance, error)

GetBot fetches the bot state for the given name

func (*KelpOS) GetProcess

func (kos *KelpOS) GetProcess(namespace string) (*Process, bool)

GetProcess gets the process tied to the provided namespace

func (*KelpOS) Mkdir

func (kos *KelpOS) Mkdir(dirPath string) error

Mkdir function with a neat error message

func (*KelpOS) QueryBotState

func (kos *KelpOS) QueryBotState(botName string) (BotState, error)

QueryBotState checks to see if the bot is actually running and returns the state accordingly

func (*KelpOS) RegisterBot

func (kos *KelpOS) RegisterBot(bot *model2.Bot) error

RegisterBot registers a new bot, returning an error if one already exists with the same name

func (*KelpOS) RegisterBotWithState

func (kos *KelpOS) RegisterBotWithState(bot *model2.Bot, state BotState) error

RegisterBotWithState registers a new bot with a given state, returning an error if one already exists with the same name

func (*KelpOS) RegisterBotWithStateUpsert

func (kos *KelpOS) RegisterBotWithStateUpsert(bot *model2.Bot, state BotState)

RegisterBotWithStateUpsert registers a new bot with a given state, it always registers the bot even if it is already registered, never returning an error

func (*KelpOS) RegisteredBots

func (kos *KelpOS) RegisteredBots() []string

RegisteredBots returns the list of registered bots

func (*KelpOS) RegisteredProcesses

func (kos *KelpOS) RegisteredProcesses() []string

RegisteredProcesses returns the list of registered processes

func (*KelpOS) SafeUnregister

func (kos *KelpOS) SafeUnregister(namespace string)

SafeUnregister ignores erros when unregistering the command at the provided namespace

func (*KelpOS) SafeUnregisterBot

func (kos *KelpOS) SafeUnregisterBot(botName string)

SafeUnregisterBot unregister a bot without any errors

func (*KelpOS) SetSilentRegistrations

func (kos *KelpOS) SetSilentRegistrations()

SetSilentRegistrations does not log every time we register and unregister commands

func (*KelpOS) Stop

func (kos *KelpOS) Stop(namespace string) error

Stop unregisters and stops the command at the provided namespace

func (*KelpOS) StreamOutput

func (kos *KelpOS) StreamOutput(command *exec.Cmd) error

StreamOutput runs the provided command in a streaming fashion

func (*KelpOS) Unregister

func (kos *KelpOS) Unregister(namespace string) error

Unregister unregisters the command at the provided namespace, returning an error if needed

type Process

type Process struct {
	Cmd     *exec.Cmd
	Stdin   io.WriteCloser
	Stdout  io.ReadCloser
	PipeIn  *os.File
	PipeOut *os.File
}

Process contains all the pieces that can be used to control a given process

Jump to

Keyboard shortcuts

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