Documentation ¶
Index ¶
- type Gofherd
- func (gf *Gofherd) AddFailureCallback(f func(*Work))
- func (gf *Gofherd) AddRetryCallback(f func(*Work))
- func (gf *Gofherd) AddSuccessCallback(f func(*Work))
- func (gf *Gofherd) CloseInputChan()
- func (gf *Gofherd) DecreaseHerdBy(num int64)
- func (gf *Gofherd) IncreasedHerdBy(num int64)
- func (gf *Gofherd) OutputChan() <-chan Work
- func (gf *Gofherd) SendWork(work Work)
- func (gf *Gofherd) SetAddr(addr string)
- func (gf *Gofherd) SetHerdSize(num int64)
- func (gf *Gofherd) SetLogger(l Logger)
- func (gf *Gofherd) SetMaxRetries(num int64)
- func (gf *Gofherd) Start()
- type Logger
- type Status
- type Work
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gofherd ¶
type Gofherd struct {
// contains filtered or unexported fields
}
Gofherd is the core struct, orchestrating all functionality. It offers all the public methods of Gofherd.
func New ¶
New initializes a new Gofherd struct. It takes in the processing logic function with the signature `func(*gf.Work) gf.Status`
func (*Gofherd) AddFailureCallback ¶
AddFailureCallback is used to setup logging. If not specified, gofherd emits no logs.
func (*Gofherd) AddRetryCallback ¶
AddRetryCallback is used to setup logging. If not specified, gofherd emits no logs.
func (*Gofherd) AddSuccessCallback ¶
AddSuccessCallback is used to setup logging. If not specified, gofherd emits no logs.
func (*Gofherd) CloseInputChan ¶
func (gf *Gofherd) CloseInputChan()
CloseInputChan is to closed the input chan. Closing the input chan when the tasks are completed will allow gofherd to shutdown gracefully.
func (*Gofherd) DecreaseHerdBy ¶
DecreaseHerdBy is used to decrease the herd size given amount
func (*Gofherd) IncreasedHerdBy ¶
IncreasedHerdBy is used to increase the herd size given amount
func (*Gofherd) OutputChan ¶
OutputChan returns the output chan, it will be closed when the processing is complete, enabling it to be read in a `for range` loop.
func (*Gofherd) SetAddr ¶
SetAddr accepts the `addr` string where the started server will be spun up.
func (*Gofherd) SetHerdSize ¶
SetHerdSize sets the herd size. The passed number is the number of gofhers spawned up for processing.
func (*Gofherd) SetLogger ¶
SetLogger is used to setup logging. If not specified, gofherd emits no logs.
func (*Gofherd) SetMaxRetries ¶
SetMaxRetries is the maximum number of times a Work unit will be tried before giving up.
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
Logger interface is accepted by SetLogger function and used to log the output. It has a single function Printf with the signature: `Printf(format string, v ...interface{})`
type Status ¶
type Status int
Status represents the outcome of "processing" Work. It can be one of Success, Retry, Failure.
const ( // Success represents a successful processing outcome. It won't be retried. Success Status = iota // Retry represents a failed processing outcome, but is retriable. It will be retried for MaxRetries. Retry // Failure represents a failed processing outcome and should not be retried again. Failure )
type Work ¶
type Work struct { ID string Body interface{} // contains filtered or unexported fields }
Work is the struct representing the work unit in Gofherd. It has an ID field which is a string, `Body` and `Result` which are an interface to store the "problem" and "solution" respectively.
func (*Work) Result ¶
func (w *Work) Result() interface{}
Result is used to access the Result of the Work unit.