worker

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Report

func Report(reporters []metrics.Reporter, period time.Duration)

Report sends periodic of worker reports

Types

type EnqueueOpts

type EnqueueOpts struct {
	RetryEnabled      bool
	MaxRetries        int
	ExponentialFactor int
	MinDelayToRetry   int
	MaxDelayToRetry   int
	MaxRandom         int
}

EnqueueOpts has retry options for worker

func NewEnqueueOpts

func NewEnqueueOpts(config *config.Config) *EnqueueOpts

NewEnqueueOpts reads from config to build *EnqueueOpts

type RPCJob

type RPCJob interface {
	// ServerDiscovery returns a serverID based on the route
	// and any metadata that is necessary to decide
	ServerDiscovery(
		route string,
		rpcMetadata map[string]interface{},
	) (serverID string, err error)

	// RPC executes the RPC
	// It is expected that if serverID is "" the RPC
	// happens to any destiny server
	RPC(
		ctx context.Context,
		serverID, routeStr string,
		reply, arg proto.Message,
	) error

	// GetArgReply returns the arg and reply of the
	// method
	GetArgReply(route string) (arg, reply proto.Message, err error)
}

RPCJob has infos to execute a rpc on worker

type Worker

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

Worker executes RPCs with retry and backoff time

func NewWorker

func NewWorker(config *config.Config) (*Worker, error)

NewWorker configures and returns a *Worker

func (*Worker) EnqueueRPC

func (w *Worker) EnqueueRPC(
	routeStr string,
	metadata map[string]interface{},
	reply, arg proto.Message,
) (jid string, err error)

EnqueueRPC enqueues rpc job to worker

func (*Worker) EnqueueRPCWithOptions

func (w *Worker) EnqueueRPCWithOptions(
	routeStr string,
	metadata map[string]interface{},
	reply, arg proto.Message,
	opts *EnqueueOpts,
) (jid string, err error)

EnqueueRPCWithOptions enqueues rpc job to worker

func (*Worker) RegisterRPCJob

func (w *Worker) RegisterRPCJob(rpcJob RPCJob) error

RegisterRPCJob registers a RPC job

func (*Worker) SetLogger

func (w *Worker) SetLogger(logger logger.Logger)

SetLogger overwrites worker logger

func (*Worker) Start

func (w *Worker) Start()

Start starts worker in another gorotine

func (*Worker) Started

func (w *Worker) Started() bool

Started returns true if worker was started

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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