pgroup

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

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

Go to latest
Published: Sep 5, 2017 License: MIT Imports: 12 Imported by: 0

README

pgroup

Build Status Go Report Card

Simple library for managing a group of processes.

Example

package main

import (
    "context"
    "log"
    "os"
    "os/signal"
    "syscall"
    "github.com/acala-io/pgroup"
)

func main() {
    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()
    sigs := make(chan os.Signal, 1)
    signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

    // create process group with prefixed stdout & stderr writers
    grp, err := pgroup.New(ctx, WithStdOut(os.Stdout), WithStdErr(os.Stdout))
    if err != nil {
        log.Fatal(err)
    }

    _, err := grp.NewProcess("server", "python myserver.py")
    if err != nil {
        log.Fatal(err)
    }

    _, err := grp.NewProcess("worker", "python myworker.py")
    if err != nil {
        log.Fatal(err)
    }

    go grp.Run()

    grp.Signal(<-sigs)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotConfigured is returned when process (or group) has not been properly configured
	ErrNotConfigured = errors.New("Process or Group not configured")
)

Functions

func New

func New(ctx context.Context, options ...groupOption) (*processGroup, error)

New creates a new group of processes.

func WithEnv

func WithEnv(env []string) groupOption

WithEnv extends the groups configured environment variables.

func WithStdErr

func WithStdErr(w io.Writer) groupOption

WithStdErr configures an io.Writer for the groups combined stderr output.

func WithStdOut

func WithStdOut(w io.Writer) groupOption

WithStdOut configures an io.Writer for the groups combined stdout output.

Types

type Process

type Process interface {
	Run() error
	AddEnv(string, string) error
	Signal(s syscall.Signal) error
	Kill() error
	GetPid() int
}

Process encapsulates the basic methods a process requires

type ProcessGroup

type ProcessGroup interface {
	Run() error
	Signal(s syscall.Signal) error
	NewProcess(name, cmd string) (Process, error)
}

ProcessGroup adds wrapper for a process' constructor

Jump to

Keyboard shortcuts

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