Documentation ¶
Index ¶
- func IsDone(ctx context.Context) bool
- func IsInvalidWorker(w Worker) (bool, string)
- func IsZero(t Task) bool
- func NewBus(conf *bus.Options) (*bus.Bus, error)
- func NewBusOptions(busType string) *bus.Options
- func NewConsumer(conf *bus.Options) (bus.Consumer, error)
- func NewProducer(conf *bus.Options) (bus.Producer, error)
- type Launcher
- type LauncherOptions
- type LauncherStats
- type Meta
- type NewWorker
- type Result
- func Alert(format string, a ...interface{}) (Result, string)
- func Completed(format string, a ...interface{}) (Result, string)
- func Failed(err error) (Result, string)
- func Failf(format string, a ...interface{}) (Result, string)
- func Interrupted() (Result, string)
- func Warn(format string, a ...interface{}) (Result, string)
- type Task
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsInvalidWorker ¶
func NewBus ¶
NewBus is a convenience wrapper around bus.NewBus. This way the user won't need to import another package for most use cases.
func NewBusOptions ¶
NewBusOptions is a convenience wrapper around bus.NewBusOptions. This way the user won't need to import another package for most use cases.
func NewConsumer ¶
NewConsumer is a convenience wrapper around bus.NewConsumer. This way the user won't need to import another package for most use cases.
Types ¶
type Launcher ¶
type Launcher struct {
// contains filtered or unexported fields
}
Launcher handles the heavy lifting of worker lifecycle, general task management and interacting with the bus.
The calling routine should listen on context.Done to know if the Launcher has shut itself down.
The calling routine can force the Launcher to shutdown by calling the cancelFunc and then listening on context.Done to know when the Launcher has shutdown gracefully.
For an example worker application look in ./apps/workers/noop/main.go.
func NewLauncher ¶
NewLauncher creates a new Launcher.
func NewLauncherFromBus ¶
func NewLauncherFromBus(newWkr NewWorker, c bus.Consumer, p bus.Producer, opt *LauncherOptions) *Launcher
NewLauncherFromBus returns a Launcher from the provided consumer and producer buses.
Usually not necessary to use directly unless the caller is providing a non-standard library consumer, producer buses.
func (*Launcher) DoTasks ¶
func (l *Launcher) DoTasks() (doneCtx context.Context, stopCncl context.CancelFunc)
DoTasks will start the task loop and immediately begin working on tasks if any are available.
The Launcher assumes the producer and consumer are fully initialized when the Launcher is created.
Will panic if not initialized with either NewLauncher or NewCPLauncher.
Calling DoTasks more than once is safe but will not do anything. If called more than once will return a copy of the same context and cancel function received the first time.
func (*Launcher) Err ¶
Err can be called after the Launcher has communicated it has finished shutting down.
If it's called before shutdown then will return nil. Will return the same error on subsequent calls.
func (*Launcher) Stats ¶ added in v0.2.0
func (l *Launcher) Stats() LauncherStats
type LauncherOptions ¶
type LauncherOptions struct { // MaxInProgress is the max number tasks // in progress at one time. MaxInProgress uint `toml:"max_in_progress" commented:"true" comment:"maximum number of workers within the application at one time"` // WorkerKillTime is how long the Launcher will // wait for a forced-shutdown worker to cleanup. WorkerKillTime time.Duration `` /* 158-byte string literal not displayed */ // LifetimeWorkers - maximum number of tasks the // Launcher will process before closing. LifetimeWorkers uint `` /* 161-byte string literal not displayed */ // DoneTopic - topic to publish to for done tasks. // Default: "done" DoneTopic string `toml:"done_topic" commented:"true" comment:"topic on which to send done tasks (error and complete results)"` // TaskType is highly encouraged to be provided. The task type is important for worker discovery and necessary // for expected functioning of the RejectBadType and IgnoreBadType options. // The default handling of a task with an non-matching task type is to create the worker anyway. TaskType string `toml:"-"` // RejectBadType will reject all task types that are not registered // with the Launcher with RegisterType. // // Note that if both RejectBadType and IgnoreBadType are true then the Launcher will // act as if only RejectBadType were true. RejectBadType bool `` /* 159-byte string literal not displayed */ // RejectBadType will reject all task types that are not registered // with the Launcher with RegisterType. // // Note that if both RejectBadType and IgnoreBadType are true then the Launcher will // act as if only RejectBadType were true. IgnoreBadType bool `toml:"ignore_bad_type" commented:"true" comment:"if true then unregistered task types are ignored and no worker is launched"` // custom logger option Logger *log.Logger `toml:"-"` }
LauncherOptions contains the options for initializing a new Launcher. The default values will likely work for most cases.
func NewLauncherOptions ¶
func NewLauncherOptions(tskType string) *LauncherOptions
LauncherOptions returns a new LauncherOptions.
type LauncherStats ¶ added in v0.2.0
type NewWorker ¶
NewWorker is a worker initializer called by the Launcher to generate a new worker for a new task.
type Result ¶
type Result string
const ( CompleteResult Result = "complete" // completed successfully (as far as the worker can tell) ErrResult Result = "error" // not completed successfully (the task outcome is bad) AlertResult Result = "alert" // no retry and an alert should be sent WarnResult Result = "warn" // non-critical failure with no retry )
func Interrupted ¶
Interrupted is a helper function that can be called when DoTask was interrupted
type Task ¶
type Task struct { Type string `json:"type"` // identifier that indicates the type of worker that knows how to complete the task Job string `json:"job,omitempty"` Info string `json:"info"` // information that tells the worker the specifics of executing the task Created string `json:"created,omitempty"` ID string `json:"id,omitempty"` // unique report id Meta string `json:"meta,omitempty"` // additional meta data as required // Result fields Result Result `json:"result,omitempty"` Msg string `json:"msg,omitempty"` Started string `json:"started,omitempty"` Ended string `json:"ended,omitempty"` // contains filtered or unexported fields }
func NewFromBytes ¶
NewFromBytes creates a Task from json bytes.
func NewWithID ¶ added in v0.3.0
NewWithID create a task with a predefined id. This is useful for changing tasks together