divider

package
v0.0.0-...-aae503c Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrJobProviderNotSpecified returns if JobProcessor started without
	// specified JobProvider.
	ErrJobProviderNotSpecified = errors.New("JobProvider not specified")

	// ErrResultReporterNotSpecified returns if JobProcessor started without
	// specified ResultReporter.
	ErrResultReporterNotSpecified = errors.New("ResultReporter not specified")

	// ErrDividerNotSpecified returns if JobProcessor started without
	// specified div.Divider for processing jobs.
	ErrDividerNotSpecified = errors.New("Divider not specified")

	// ErrLoggerNotSpecified returned if JobProcessor started without
	// specified log.Logger.
	ErrLoggerNotSpecified = errors.New("Logger not specified")

	// ErrArg1Missing specifies that a job does not have field "arg1"
	ErrArg1Missing = NewNonTerminalError(errors.New(`"arg1" field missing`))

	// ErrArg2Missing specifies that a job does not have field "arg2"
	ErrArg2Missing = NewNonTerminalError(errors.New(`"arg2" field missing`))
)

Functions

This section is empty.

Types

type Job

type Job struct {
	Arg1, Arg2 int
	Valid      bool
}

Job to be processed in accordance to the aptitude test requirements.

type JobProcessor

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

JobProcessor does all the job - processes jobs in accordance to the aptitude test requirements.

func NewJobProcessor

func NewJobProcessor() *JobProcessor

NewJobProcessor creates a new JobProcessor.

func (*JobProcessor) Processed

func (p *JobProcessor) Processed() uint64

Processed returns processed jobs counter.

func (*JobProcessor) SetDivider

func (p *JobProcessor) SetDivider(d div.Divider) *JobProcessor

SetDivider sets division method.

func (*JobProcessor) SetJobProvider

func (p *JobProcessor) SetJobProvider(prov JobProvider) *JobProcessor

SetJobProvider specifies a provider of jobs to be processed.

func (*JobProcessor) SetLogger

func (p *JobProcessor) SetLogger(l *log.Logger) *JobProcessor

SetLogger specifies a logger to be used with JobProcessor and its workers.

func (*JobProcessor) SetResultReporter

func (p *JobProcessor) SetResultReporter(rrep ResultReporter) *JobProcessor

SetResultReporter specifies a writer that will be used with JobProcessor to write processing results.

func (*JobProcessor) SetWorkersCount

func (p *JobProcessor) SetWorkersCount(workers uint) *JobProcessor

SetWorkersCount specifies count of workers to be created to handle jobs.

func (*JobProcessor) Start

func (p *JobProcessor) Start() error

Start initializes worker pool and begins processing of jobs.

func (*JobProcessor) Stop

func (p *JobProcessor) Stop()

Stop cancels reading, what, in turn, closes the worker pool and stops writing results.

type JobProvider

type JobProvider interface {
	Next(*Job) error
	More() bool
}

JobProvider supplies new jobs to JobProcessor. JobProvider must return error of NonTerminalError type if provided jobs was is invalid.

type JobResult

type JobResult struct {
	ID    uint64
	Value int
	Valid bool
}

JobResult represents an outcome of a particular job processing. ID member is a sequential number of the corresponding job. Valid member specifies whether the job was processed correctly.

type NonTerminalError

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

NonTerminalError specifies that JobProcessor must skip processing of the job. The error should only raised by JobProvider.

func NewNonTerminalError

func NewNonTerminalError(err error) *NonTerminalError

NewNonTerminalError creates new NonTerminalError that wraps provided one.

func (*NonTerminalError) Error

func (e *NonTerminalError) Error() string

type ResultReporter

type ResultReporter interface {
	Report(*JobResult) error
}

ResultReporter delievers results of job processing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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