Version: v0.0.0-...-ee5db13 Latest Latest

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

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



Package worker provides a library framework for processes that execute Coordinate work units.



This section is empty.


This section is empty.


This section is empty.


type Worker

type Worker struct {
	// Namespace identifies the Coordinate namespace from which
	// work is performed.  This field is required when creating
	// a Worker.
	Namespace coordinate.Namespace

	// Tasks defines the tasks this Worker is capable of running.
	// Work specs must declare a runtime consistent with this
	// worker's runtime settings (by default, that's "runtime: go"),
	// and also have a "task:" field that names one of the tasks in
	// this map. If a work spec has no "task:", the work spec name
	// is looked up here instead.
	// The task function is called with a context and a slice of
	// at least one attempt.  The context will be canceled when
	// the worker is stopped or if one of the attempts is nearing
	// is expiration time.  The worker can take any reasonable action
	// in response to being signaled, but generally it should stop
	// doing further work and mark all of the attempts as failed.
	// There is guaranteed to be at least one attempt.  All attempts
	// are for the same worker and for the same work spec.
	Tasks map[string]func(context.Context, []coordinate.Attempt)

	// WorkerID provides the name of the worker as seen through the
	// Coordinate API.  If unset, a worker ID will be generated.
	WorkerID string

	// Concurrency states how many sets of attempts should run in
	// parallel.  If unset, uses runtime.NumCPU().
	Concurrency int

	// PollInterval states how often the worker should try to get
	// more work if the previous attempt(s) returned nothing.  If
	// unset, defaults to 1 second.
	PollInterval time.Duration

	// HeartbeatInterval states how often the worker should report
	// its status in the Coordinate worker data, and check for
	// work units that are about to expire.  If unset, defaults to
	// 15 seconds.
	HeartbeatInterval time.Duration

	// MaxAttempts limits the number of attempts that will be
	// returned; it is exactly the
	// coordinate.AttemptRequest.NumberOfWorkUnits parameter.  If
	// unset, use 100.  Note that individual work specs can also
	// limit the number of attempts by setting a "max_getwork"
	// key.
	MaxAttempts int

	// ErrorHandler is called when an error occurs in the worker
	// main loop.
	ErrorHandler func(error)

	// Clock defines a time source for the worker.  If the
	// Coordinate backend was created with an alternate time
	// source, this should match that time source.  Only test code
	// should need to set this.  If unset, uses a time source
	// backed by real wall-clock time.
	Clock clock.Clock

	// Runtimes sets the language runtimes that should be used
	// with this worker. When nil, a default value of ["go"] is
	// used.
	Runtimes []string
	// contains filtered or unexported fields

Worker is foo.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Run runs work units from Coordinate forever, or until the provided context is cancelled. If it returns, either there was a startup error connecting to Coordinate, in which case the corresponding error is returned, or execution was cancelled, returning nil. If there is an error while trying to get attempts it is ignored.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL