dispatcher

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskFailed = iota
	TaskDone
	TaskActive
	TaskPending
	TaskDropped
)

Variables

View Source
var (
	DispatcherQueueLength = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "dispatcher_queue_length",
	})
	DispatcherTasksActive = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "dispatcher_tasks_active",
	})
	DispatcherTasksQueued = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "dispatcher_tasks_queued",
	})
	DispatcherTasksDropped = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "dispatcher_tasks_dropped",
	})
	DispatcherTasksDone = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "dispatcher_tasks_done",
	}, []string{"worker_id"})
	DispatcherTasksFailed = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "dispatcher_tasks_failed",
	}, []string{"worker_id"})
)
View Source
var ErrInvalidPayload = errors.New("invalid payload")

Functions

func RegisterMetrics added in v0.10.11

func RegisterMetrics()

func SetLogger

func SetLogger(l *zap.SugaredLogger)

func WaitUntilTrue

func WaitUntilTrue(ctx context.Context, between time.Duration, f func() bool) error

Types

type Dispatcher

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

func Start

func Start(workers int, wl Workload, tasksLen int) Dispatcher

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(payload interface{}) *Result

func (Dispatcher) Stop

func (d Dispatcher) Stop()

type Result added in v0.7.0

type Result struct {
	Status int
	Error  error
}

func (Result) Done added in v0.7.0

func (r Result) Done() bool

func (Result) Failed added in v0.7.0

func (r Result) Failed() bool

type Task

type Task struct {
	Payload    interface{}
	Dispatcher *Dispatcher
	// contains filtered or unexported fields
}

type Worker

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

func NewWorker

func NewWorker(id int, workerPool chan chan Task, wl Workload, gwait *sync.WaitGroup) Worker

func (*Worker) Start

func (w *Worker) Start()

Start starts reading from tasks channel

func (*Worker) Stop

func (w *Worker) Stop()

Stop stops the wl invocation cycle (it will finish the current wl).

type Workload

type Workload interface {
	Do(Task) error
}

Jump to

Keyboard shortcuts

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