worker

package
v0.0.0-...-83a686f Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

Worker SDK

This provides a basic workloop that:

  1. Gracefully exits without losing tasks (with a configurable timeout)
  2. Handles API errors
  3. Groups Task claims from multiple Queues in a single request for every run of the loop

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Failure

type Failure map[string]interface{}

func (Failure) Error

func (f Failure) Error() string

type QueuesToHandles

type QueuesToHandles map[string]TaskHandler

type Success

type Success map[string]interface{}

type TaskHandle

type TaskHandle struct {
	Task *models.TaskTask
	// contains filtered or unexported fields
}

func (*TaskHandle) IsUnclaimed

func (h *TaskHandle) IsUnclaimed() bool

func (*TaskHandle) ReportIn

func (h *TaskHandle) ReportIn(data *map[string]interface{}) error

Submit a report with optional data to prevent the task from timing out

func (*TaskHandle) Unclaim

func (h *TaskHandle) Unclaim() error

Unclaims the current task and puts it back on the queue

type TaskHandler

type TaskHandler interface {
	Handle(handle TaskHandle) (*Success, *Failure)
}

A Handler taks a TaskHandle and performs a function on it; the handle can be used to report on a given task (also bumps the timeout), unclaim the task (causes ignoring of the return values), or completed as either a success or failure.

type WorkLoop

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

A work loop that submits Task claim requests to the server based on Queues and the Handlers that are interested in the Tasks from each Queue. Run() the returned loop to begin processing.

The claim is submitted as a single request to save bandwidth, and then demuxed to the handlers

func NewWorkLoop

func NewWorkLoop(config config.TasquesWorker, queuesToHandles QueuesToHandles) WorkLoop

func (*WorkLoop) Run

func (w *WorkLoop) Run() error

Runs the work loop and listens to sig int and sig term to gracefully exit to make sure we don't lose any Tasks that have been claimed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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