supervisor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: Apache-2.0 Imports: 0 Imported by: 0

README

pkg/supervisor

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

Overview

This package provide an abstraction and functionality for watching plugin's processes. With current abstraction, we should be able to provide a mechanism to restart plugin's process or at least do something when plugin cannot be reached.

Types


// Payload used as main data when some plugin from some host indicated as error / cannot be reached
type Payload struct {
	Host   string
	Plugin string
}

// Driver used as main interface to run supervisor activities
type Driver interface {
	Watch() <-chan *Payload
	OnError(event *Payload, handlers ...OnErrorHandler)
}

// OnErrorHandler used as main type for handling plugin's error
type OnErrorHandler func(payload *Payload)

Usages

import (
	"github.com/quadroops/goplugin/pkg/supervisor"
)

handler1 := func(p *supervisor.Payload) {
    assert.NotEmpty(t, p.Host)
    assert.NotEmpty(t, p.Plugin)

    assert.Equal(t, p.Host, "test-host")
    assert.Equal(t, p.Plugin, "test-plugin")
}

handler2 := func(p *supervisor.Payload) {
    assert.Equal(t, p.Host, "test-host")
    assert.Equal(t, p.Plugin, "test-plugin")
}

// d is a driver implement `Driver` interface
// handler1 / handler2 is a function which implement `OnErrorHandler` signature
s := supervisor.New(d, handler1, handler2)

// run supervisor
s.Start().Handle()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	Watch() <-chan *Payload
	OnError(event *Payload, handlers ...OnErrorHandler)
}

Driver used as main interface to run supervisor activities

type OnErrorHandler

type OnErrorHandler func(payload *Payload)

OnErrorHandler used as main type for handling plugin's error

type Payload

type Payload struct {
	Host   string
	Plugin string
}

Payload used as main data when some plugin from some host indicated as error / cannot be reached

type Runner

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

Runner is main struct to store supervisor's driver

func New

func New(driver Driver, handlers ...OnErrorHandler) *Runner

New used to create new instance of supervisor

func (*Runner) Handle

func (r *Runner) Handle()

Handle used to listen to error events, by default we put main process to listening events inside a goroutine

func (*Runner) Start

func (r *Runner) Start() *Runner

Start used to start supervisor's process

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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