process

package
v1.0.0-alpha.0 Latest Latest
Warning

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

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

README

pkg/process

Package: github.com/quadroops/goplugin/pkg/process

Overview

This package provide functionalities to manage subprocesses, including running and killing process.

Flows:

  • Run individual plugin, based on plugin's exec path. A host can run a plugin based on their plugin's name
  • When running a plugin, a host should be able to wait based plugin's exec_time to make sure plugin has been running successfully
  • Each of executed plugins, will be isolated and have their own process, mapped using plugin's name and their ID
  • A host can kill individual or all executed plugins based on their ID
  • When a host killed, should be able to kill all executed plugins, to make sure there are no zombie process running on OS

Behaviors

  • Run individual plugin based on plugin's name
  • Kill stop individual plugin's process
  • KillAll kill all running plugins from the Registry

Usages

import (
	"github.com/quadroops/goplugin/pkg/process"
	"github.com/quadroops/goplugin/pkg/process/driver"
)

p := process.New(
    driver.NewSubProcess(), 
    driver.NewProcesses(driver.NewRegistry()),
)

// run new subprocess
ch, err := p.Run(1, "test", "test", 1001)
if err != nil {
    // error handling
}

// get plugin info
plugin := <-ch

// kill plugin
err = p.Kill() 

// kill all plugins
errs := p.KillAll()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID int

ID is an alias for os PID

type Instance

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

Instance used to setup new process instance

func New

func New(runner Runner, processes ProcessesBuilder) *Instance

New used to create new process instance

func (*Instance) IsReady

func (i *Instance) IsReady(name string) bool

IsReady used to check if requested plugin started or not

func (*Instance) Kill

func (i *Instance) Kill(name string) error

Kill used to kill individual plugin's process

func (*Instance) KillAll

func (i *Instance) KillAll() []error

KillAll used to kill all available plugin's processes

func (*Instance) Run

func (i *Instance) Run(toWait int, name, command string, port int, args ...string) (<-chan Plugin, error)

Run used to start new subprocess

func (*Instance) Watch

func (i *Instance) Watch(p <-chan Plugin, err error)

Watch used to put current running plugin to list of rxgo.Item

type OnError

type OnError func(err error)

OnError used to catch error

type Plugin

type Plugin struct {
	Kill   context.CancelFunc
	Name   string
	ID     ID
	Stdout *utils.Buffer
	Stderr *utils.Buffer
}

Plugin used when running a plugin to save their state and process id information

type ProcessesBuilder

type ProcessesBuilder interface {
	// Remove used to remove plugin from processes list
	Remove(string) error

	// Add used to adding new process
	Add(Plugin) error

	// Reset should reset all processes
	Reset()

	// IsExist used to check if plugin has a process or not
	IsExist(name string) bool

	// Listen used to start observe available streams, if any
	Listen() (rxgo.Observable, error)

	// Get used to fetch the plugin info from list of processes or from
	// data registry
	Get(string) (Plugin, error)
}

ProcessesBuilder is main interface to manipulate list of available processes

type RegistryBuilder

type RegistryBuilder interface {
	Register(string, Plugin)
	IsExist(string) bool
	Delete(string)
	Get(string) (Plugin, error)
	Reset()
}

RegistryBuilder used to as an interface to build registry of processes registry is like an indexing in database, used to prevent system to scanning all processes

type Runner

type Runner interface {
	Run(toWait int, name, execCommand string, port int, args ...string) (<-chan Plugin, error)
}

Runner used as main interface to start new subprocess

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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