pm

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2017 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AggreagteAverage    = "A"
	AggreagteDifference = "D"
)
View Source
const (
	StreamBufferSize = 1000
)

Variables

View Source
var (
	UnknownCommandErr = errors.New("unkonw command")
	DuplicateIDErr    = errors.New("duplicate job id")
)

Global command ProcessConstructor registery

Functions

func GetProcessFactory

func GetProcessFactory(cmd *core.Command) process.ProcessFactory

NewProcess creates a new process from a command

func RegisterCmd

func RegisterCmd(cmd string, exe string, workdir string, cmdargs []string, env map[string]string)

RegisterCmd registers a new command (extension) so it can be executed via commands

func UnregisterCmd

func UnregisterCmd(cmd string)

UnregisterCmd removes an extension from the global registery

Types

type DelayHook

type DelayHook struct {
	NOOPHook

	Delay  time.Duration
	Action func()
	// contains filtered or unexported fields
}

func (*DelayHook) Tick

func (h *DelayHook) Tick(delay time.Duration)

type ExitHook

type ExitHook struct {
	NOOPHook

	Action func(bool)
	// contains filtered or unexported fields
}

func (*ExitHook) Exit

func (h *ExitHook) Exit(state string)

type MatchHook

type MatchHook struct {
	NOOPHook
	Match  string
	Action func(msg *stream.Message)
	// contains filtered or unexported fields
}

func (*MatchHook) Message

func (h *MatchHook) Message(msg *stream.Message)

type MessageHandler

type MessageHandler func(*core.Command, *stream.Message)

type MeterHandler

type MeterHandler func(cmd *core.Command, p *psutil.Process)

MeterHandler represents a callback type

type NOOPHook

type NOOPHook struct {
}

func (*NOOPHook) Exit

func (h *NOOPHook) Exit(state string)

func (*NOOPHook) Message

func (h *NOOPHook) Message(msg *stream.Message)

func (*NOOPHook) PID

func (h *NOOPHook) PID(pid int)

func (*NOOPHook) Tick

func (h *NOOPHook) Tick(delay time.Duration)

type PIDHook

type PIDHook struct {
	NOOPHook

	Action func(pid int)
	// contains filtered or unexported fields
}

func (*PIDHook) PID

func (h *PIDHook) PID(pid int)

type PM

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

PM is the main process manager.

func GetManager

func GetManager() *PM

TODO: That's not clean, find another way to make this available for other code

func InitProcessManager

func InitProcessManager(maxJobs int) *PM

NewPM creates a new PM

func (*PM) AddMessageHandler

func (pm *PM) AddMessageHandler(handler MessageHandler)

AddMessageHandler adds handlers for messages that are captured from sub processes. Logger can use this to process messages

func (*PM) AddResultHandler

func (pm *PM) AddResultHandler(handler ResultHandler)

AddResultHandler adds a handler that receives job results.

func (*PM) AddRouteResultHandler

func (pm *PM) AddRouteResultHandler(route core.Route, handler ResultHandler)

func (*PM) AddStatsHandler added in v0.11.0

func (pm *PM) AddStatsHandler(handler StatsHandler)

AddStatsFlushHandler adds handler to stats flush.

func (*PM) Aggregate added in v0.11.0

func (pm *PM) Aggregate(op, key string, value float64, tags string)

func (*PM) Kill

func (pm *PM) Kill(cmdID string) error

Kill kills a process by the cmd ID

func (*PM) Killall

func (pm *PM) Killall()

Killall kills all running processes.

func (*PM) NewRunner

func (pm *PM) NewRunner(cmd *core.Command, factory process.ProcessFactory, hooks ...RunnerHook) (Runner, error)

func (*PM) PushCmd

func (pm *PM) PushCmd(cmd *core.Command)

RunCmd runs and manage command

func (*PM) PushCmdToQueue

func (pm *PM) PushCmdToQueue(cmd *core.Command)

RunCmdQueued Same as RunCmdAsync put will queue the command for later execution when there are no other commands runs on the same queue.

The queue name is retrieved from cmd.Args[queue]

func (*PM) Register

func (pm *PM) Register(g process.GetPID) error

func (*PM) Run

func (pm *PM) Run()

Run starts the process manager.

func (*PM) RunCmd

func (pm *PM) RunCmd(cmd *core.Command, hooks ...RunnerHook) (Runner, error)

func (*PM) RunSlice

func (pm *PM) RunSlice(slice settings.StartupSlice)

RunSlice runs a slice of processes honoring dependencies. It won't just start in order, but will also make sure a service won't start until it's dependencies are running.

func (*PM) Runners

func (pm *PM) Runners() map[string]Runner

Processes returs a list of running processes

func (*PM) WaitPID

func (pm *PM) WaitPID(pid int) syscall.WaitStatus

type ResultHandler

type ResultHandler func(cmd *core.Command, result *core.JobResult)

ResultHandler represents a callback type

type Runner

type Runner interface {
	Command() *core.Command
	Run()
	Terminate()
	Process() process.Process
	Wait() *core.JobResult
	StartTime() int64
}

func NewRunner

func NewRunner(manager *PM, command *core.Command, factory process.ProcessFactory, hooks ...RunnerHook) Runner

NewRunner creates a new runner object that is bind to this PM instance.

:manager: Bind this runner to this PM instance :command: Command to run :factory: Process factory associated with command type. :hooksDelay: Fire the hooks after this delay in seconds if the process is still running. Basically it's a delay for if the

command didn't exit by then we assume it's running successfully
values are:
	- 1 means hooks are only called when the command exits
	0   means use default delay (default is 2 seconds)
	> 0 Use that delay

:hooks: Optionals hooks that are called if the process is considered RUNNING successfully.

The process is considered running, if it ran with no errors for 2 seconds, or exited before the 2 seconds passes
with SUCCESS exit code.

type RunnerHook

type RunnerHook interface {
	Tick(delay time.Duration)
	Message(msg *stream.Message)
	Exit(state string)
	PID(pid int)
}

type StateMachine

type StateMachine interface {
	Wait(key ...string) bool
	WaitAll()
	Release(ket string, state bool) error
}

func NewStateMachine

func NewStateMachine(keys ...string) StateMachine

type StatsHandler added in v0.11.0

type StatsHandler func(operation string, key string, value float64, tags string)

StatsFlushHandler represents a callback type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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