conveyor

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 18 Imported by: 0

README

Conveyor

The support of the multi-concurrent design patterns.

Common Conveyor schema:

alt text

Godoc

Installation

conveyor requires a Go version with Modules support and uses import versioning. So please make sure to initialize a Go module before installing conveyor:

go mod init github.com/my/repo
go get github.com/iostrovok/conveyor

Import:

import (
	"github.com/iostrovok/conveyor"
	"github.com/iostrovok/conveyor/faces"
	"github.com/iostrovok/conveyor/input"
)

Quickstart

See example/quickstart


package main

import (
	"context"
	"fmt"
	"log"

	"github.com/iostrovok/conveyor"
	"github.com/iostrovok/conveyor/faces"
	"github.com/iostrovok/conveyor/input"
)

type MySimpleHandler struct {
	faces.EmptyHandler
	name faces.Name
}

func Handler(name faces.Name) (faces.IHandler, error) {
	return &MySimpleHandler{name: name}, nil
}

func (m *MySimpleHandler) Run(item faces.IItem) error {
	fmt.Printf("MySimpleHandler %s => %d]: %s\n", m.name, item.GetID(), item.Get().(string))
	return nil
}

func main() {
	// create new conveyor
	myMaster := conveyor.New(20, faces.ChanStdGo, "my-app")

	// set up simple handler
	if err := myMaster.AddHandler("handler", 2, 6, Handler); err != nil {
		log.Fatal(err)
	}

	// start our conveyor
	if err := myMaster.Start(context.Background()); err != nil {
		log.Fatal(err)
	}

	for i := 0; i < 100; i++ {
        // process our string-item
		item := input.New().Data(fmt.Sprintf("item: %d", i+1))
		myMaster.Run(item)
	}

	// wait while conveyor is working
	myMaster.WaitAndStop()
}

Documentation

Overview

Package conveyor implements a conveyor for process items step by step.

Index

Constants

View Source
const DefaultMetricPeriodDuration = 10 * time.Second

DefaultMetricPeriodDuration set up by default default for send/print metric.

Variables

This section is empty.

Functions

func New

func New(workBranchLength int, chanType faces.ChanType, name string) faces.IConveyor

New is a simple constructor.

func NewTest added in v0.0.21

func NewTest(workBranchLength int, chanType faces.ChanType, name string, testObject faces.ITestObject) faces.IConveyor

NewTest is full constructor for accurate configuration in test mode.

Types

type Conveyor

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

Conveyor is main top structure supported the faces.IConveyor interface. It is exported to possibility of debug in outside applications.

func (*Conveyor) AddErrorHandler

func (c *Conveyor) AddErrorHandler(manageName faces.Name, minCount, maxCount int, handler faces.GiveBirth) error

AddErrorHandler adds custom error handler for processing the errors which were returned with work handler. Multiple custom error handlers are allowed. If custom error handler returned error the conveyor logs the error but doesn't process.

func (*Conveyor) AddFinalHandler

func (c *Conveyor) AddFinalHandler(name faces.Name, minCount, maxCount int, handler faces.GiveBirth) error

AddFinalHandler adds customer final handler as the latest handler from all. Only single customer final handler is allow. If custom final handler returned error the conveyor doesn't process and log it.

func (*Conveyor) AddHandler

func (c *Conveyor) AddHandler(name faces.Name, minCount, maxCount int, handler faces.GiveBirth) error

AddHandler adds customer handler. Parameter name should be unique. minCount should be less or equal the maxCount and great than zero. The order of adding handlers are important. The handlers are called in the same order as they were added.

func (*Conveyor) DefaultPriority added in v0.0.3

func (c *Conveyor) DefaultPriority() int

DefaultPriority returns the current default priority. The current default priority is used if a priority is not set up for item.

func (*Conveyor) GetDefaultPriority

func (c *Conveyor) GetDefaultPriority() int

GetDefaultPriority returns the default priority of items. It makes sense if priority queue is used.

func (*Conveyor) GetName

func (c *Conveyor) GetName() string

GetName is a simple getter for name property.

func (*Conveyor) Init added in v0.0.2

func (c *Conveyor) Init(workBranchLength int, chType faces.ChanType, name string, testObject faces.ITestObject) faces.IConveyor

Init is full constructor for accurate configuration.

func (*Conveyor) MetricPeriod

func (c *Conveyor) MetricPeriod(duration time.Duration) faces.IConveyor

MetricPeriod sets up the period between metric evaluations. By default 10 second.

func (*Conveyor) Run

func (c *Conveyor) Run(i faces.IInput)

Run creates the new item over interface and sends to conveyor. If priority queue is used the default priority will be set up.

func (*Conveyor) RunRes

func (c *Conveyor) RunRes(i faces.IInput) (interface{}, error)

RunRes creates the new item over interface, sends to conveyor and returns result.

func (*Conveyor) RunResTest added in v0.0.19

func (c *Conveyor) RunResTest(i faces.IInput, testObject faces.ITestObject) (interface{}, error)

RunResTest creates the new item over interface, sends to conveyor and returns result.

func (*Conveyor) RunTest added in v0.0.19

func (c *Conveyor) RunTest(i faces.IInput, testObject faces.ITestObject)

RunTest creates the new item over interface and sends to conveyor. If priority queue is used the default priority will be set up.

func (*Conveyor) SetDefaultPriority

func (c *Conveyor) SetDefaultPriority(defaultPriority int)

SetDefaultPriority sets the priority of items. It makes sense if priority queue is used. If priority is not set up it equals the 0 (defaultPriority constant).

func (*Conveyor) SetMasterNode

func (c *Conveyor) SetMasterNode(addr string, masterNodePeriod time.Duration)

SetMasterNode sets the internet address master node. Master node allow to get information online about current conveyor. see more information github.com/iostrovok/conveyormaster.

func (*Conveyor) SetName

func (c *Conveyor) SetName(name string) faces.IConveyor

SetName is a simple setter for name property.

func (*Conveyor) SetTracer

func (c *Conveyor) SetTracer(tr faces.ITrace, duration time.Duration) faces.IConveyor

SetTracer sets up the tracer with ITrace interface.

func (*Conveyor) SetWorkersCounter

func (c *Conveyor) SetWorkersCounter(wc faces.IWorkersCounter) faces.IConveyor

SetWorkersCounter sets up the tracer with IWorkersCounter interface. WorkersCounter rules the number of current worked handlers.

func (*Conveyor) Start

func (c *Conveyor) Start(ctx context.Context) error

Start starts the conveyor.

func (*Conveyor) Statistic

func (c *Conveyor) Statistic() *nodes.SlaveNodeInfoRequest

Statistic returns the information about current stage of conveyor.

func (*Conveyor) Stop

func (c *Conveyor) Stop()

Stop stops the conveyor. Processing of items will be interrupted.

func (*Conveyor) WaitAndStop

func (c *Conveyor) WaitAndStop()

WaitAndStop waits while all handler are finished and exits. Processing of items will not be interrupted.

func (*Conveyor) WorkBench added in v0.2.0

func (c *Conveyor) WorkBench() faces.IWorkBench

WorkBench is a simple getter

Directories

Path Synopsis
example
quickstart command
simple command
Package faces implements the full list of Interfaces.
Package faces implements the full list of Interfaces.
mmock
Package mmock is a generated GoMock package.
Package mmock is a generated GoMock package.
Package input implements the faces.IInput interface.
Package input implements the faces.IInput interface.
Package internalmanager is an internal package.
Package internalmanager is an internal package.
Package item implements the faces.IItem interface.
Package item implements the faces.IItem interface.
protobuf
Package queues implements the IChan interface and provides 3 simples realization of them.
Package queues implements the IChan interface and provides 3 simples realization of them.
priorityqueue
Package priorityqueue supports the priority queues for using them in conveyor.
Package priorityqueue supports the priority queues for using them in conveyor.
stack
Package stack supports the stack queues LIFO (or FILO) for using them in conveyor.
Package stack supports the stack queues LIFO (or FILO) for using them in conveyor.
std
Package std supports queue with standard GO-channels for using them in conveyor.
Package std supports queue with standard GO-channels for using them in conveyor.
Package slavenode support the slave mode and sends statistic to master node.
Package slavenode support the slave mode and sends statistic to master node.
Package testobject realizes the ITestObject interface.
Package testobject realizes the ITestObject interface.
Package tracer supports the simple realization of ITrace.
Package tracer supports the simple realization of ITrace.
Package workbench supports the simple realization of ITrace.
Package workbench supports the simple realization of ITrace.
Package workers is an internal package.
Package workers is an internal package.
Package workerscounter rules the number of current worked handlers.
Package workerscounter rules the number of current worked handlers.

Jump to

Keyboard shortcuts

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