Documentation ¶
Overview ¶
Package worker is a set of helpers for implementing common features of robot workers (see package job for more information about what a worker is). It is not required to use this package, but it helps for the simple cases.
Index ¶
- func EquivalentAction(a, b Action) bool
- func NeedsRetry(reason string, retryStrings ...string) error
- func RetryFunction(ctx context.Context, maxAttempts int, delay time.Duration, task func() error) error
- type Action
- type Actions
- type Input
- type Manager
- type Task
- type TaskRetryError
- type Worker
- type Workers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EquivalentAction ¶
EquivalentAction returns true if an action is the same task being performed on the same devices.
func NeedsRetry ¶
NeedsRetry is used to check if a string signals a retry attempt in a task. "text file busy" is the main cause for retry attempts, but if extra checks are necessary they can be passed into they variadic argument. This is the idiomatic method of creating a TaskRetryError and if no need for a retry exists it returns nil.
Types ¶
type Action ¶
type Action interface { proto.Message // Init is called as you add input and target device pairs to the manager. // It is invoked with the action id to use, the input the manager was given, and // the worker that the task is going to be posted to. Init(id string, input Input, w *job.Worker) // JobID must return the id that was handed to Init. JobID() string // JobHost must return the host of the worker that was handed to Init. JobHost() string // JobTarget must return the target of the worker that was handed to Init. JobTarget() string // JobInput must return the input that was handed to Init. JobInput() Input }
Action is the interface to the specific action type for a given of the Actions store.
type Actions ¶
type Actions struct {
// contains filtered or unexported fields
}
Actions is a struct to manage a persistent set of actions.
type Input ¶
Input is the interface that must be implemented by anything that wants to be the input to an action.
type Manager ¶
type Manager struct { //Actions holds the persisted list of actions the service has had added to it. Actions Actions // Workers holds the dynamic list of live workers for the service. Workers Workers }
Manager is a helper for writing local manager implementation of worker types (such as trace and replay). It has all the code needed to manage and persist the list of workers and actions those workers are performing.
func (*Manager) Do ¶
Do is called to add a new action to the service. It is handed the id of the target device to run it on, and the inputs to the action. The active worker that owns the target device will be looked up, and then a new action created for the target worker and provided input will be added to the store.
func (*Manager) Init ¶
func (m *Manager) Init(ctx context.Context, library record.Library, jobs job.Manager, op job.Operation, nullAction Action, nullTask Task) error
Init is called to initialised the action store from the supplied library. It loads the action ledger and prepares the empty worker list. The op is the type of action this manager supports, the nullAction is the empty version of the action the manager holds, and the nullTask is the empty version of the task sent to the managers workers.
type Task ¶
type Task interface { proto.Message // Init is called as you add input and target device pairs to the manager. // It is invoked with the action id to post results to, the input the manager was given, and // the worker that the task is going to be posted to. Init(id string, input Input, w *job.Worker) }
Task is the interface to something that can be sent to a worker. It should always contain the inputs to the action, and the id of the action to attach results to.
type TaskRetryError ¶
type TaskRetryError struct {
Reason string
}
TaskRetryError is used to communicate that an action Failed in such a way that the task should attempt a retry. It simply contains the reason for the retry.
func (TaskRetryError) Error ¶
func (e TaskRetryError) Error() string
Error returns the reason for the retry
type Worker ¶
type Worker struct { // Info is the persistable information about a worker. Info *job.Worker // contains filtered or unexported fields }
Worker is the representation of a live object that can perform actions.
type Workers ¶
type Workers struct {
// contains filtered or unexported fields
}
Workers is the non persisted list of live workers.
func (*Workers) Find ¶
Find searches the live worker set to find the one that is managing a given target device.
func (*Workers) Register ¶
func (w *Workers) Register(ctx context.Context, host *device.Instance, target *device.Instance, handler interface{}) error
Register is called to add a new worker to the active set. It takes the host and target device for the worker, which may be the same, and a handler that will be passed all the task objects that are sent to the worker.