jobmanager

package module
v0.0.0-...-e92d442 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2017 License: BSD-2-Clause Imports: 11 Imported by: 0

README

go-jobmanager

GODOC

  • run a subprocess pool
  • configure min and max subprocesses, this library will grow the pool as jobs are needed
  • configure maximum RSS, this lib will rotate jobs who's processes exceeds the RSS

Jobmanager's are goroutine safe, individual jobs returned by Reserve() are not.

example

the jobmanager needs a Runner passed in

type cmdTester struct {
	path string
	args []string
	dir  string
}

// impelementes the runner interface
func (c *cmdTester) Run(i uint64) *exec.Cmd {
	return &exec.Cmd{
		Path: c.path,
		Args: c.args,
		Dir:  c.dir,
	}

}


jb := NewJobManager(
	&cmdTester{
		path: bin,
		args: args,
		dir:  "testdata",
	},
	"",
	"",
	t.Name(),
	min, max, // 1 min proc, 10 maxprocs
	maxrss, //52 MB
)

jb.Run(bookeepIntervalMs)
j := jb.Reserve()
if resp, release, err := j.Communicate([]byte("test command!!!!\n")); err != nil {
	panic(err)
}

fmt.Printf("%v\n", resp)
// library manages buffer pools, so release the bytes when done
release()

// return the job (worker) back to the manager
// any jobs that returned EOF on their stdout pipe will be cycled properly
jb.Release(j)

// shuts down all subprocs
jb.Stop()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Communicator

type Communicator interface {
	Communicate([]byte) ([]byte, func(), error)
}

type Initializer

type Initializer interface {
	Init(uint64, Communicator) error
}

type Jobmanager

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

func NewJobManager

func NewJobManager(run Runner, namespace, subsystem, jobname string,
	min, max int64, maxrss uint64) (*Jobmanager, error)

func NewJobManagerWithTimeout

func NewJobManagerWithTimeout(run Runner, namespace, subsystem, jobname string,
	min, max int64, maxrss uint64, d time.Duration) (*Jobmanager, error)

func (*Jobmanager) Metrics

func (jb *Jobmanager) Metrics() []prometheus.Collector

func (*Jobmanager) Release

func (jb *Jobmanager) Release(j *job)

func (*Jobmanager) Reserve

func (jb *Jobmanager) Reserve() *job

func (*Jobmanager) Run

func (jb *Jobmanager) Run(bookinterval time.Duration)

func (*Jobmanager) Stop

func (jb *Jobmanager) Stop()

type Runner

type Runner interface {
	Run(uint64) *exec.Cmd
}

Jump to

Keyboard shortcuts

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