worker

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackgroundWorker

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

BackgroundWorker is a worker that runs tasks on background

func New

func New() *BackgroundWorker

New creates a new BackgroundWorker

func (*BackgroundWorker) Enqueue

func (w *BackgroundWorker) Enqueue(task Task)

Enqueue a task on current worker

func (*BackgroundWorker) Length

func (w *BackgroundWorker) Length() int64

Length from current queue length

func (*BackgroundWorker) Logger

func (w *BackgroundWorker) Logger() log.Logger

Logger from current worker

func (*BackgroundWorker) Run

func (w *BackgroundWorker) Run(id string)

Run initializes the worker loop

func (*BackgroundWorker) Shutdown added in v0.13.0

func (w *BackgroundWorker) Shutdown(ctx context.Context) error

Shutdown current worker

func (*BackgroundWorker) Use

func (w *BackgroundWorker) Use(middleware MiddlewareFunc)

Use this to inject worker dependencies

type Context

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

Context holds references to services available for jobs

func NewContext

func NewContext(workerID, taskName string, logger log.Logger) *Context

NewContext creates a new context

func (*Context) BaseURL

func (c *Context) BaseURL() string

BaseURL from current context

func (*Context) Failure added in v0.12.0

func (c *Context) Failure(err error) error

Failure logs details of error

func (*Context) Logger

func (c *Context) Logger() log.Logger

Logger from current context

func (*Context) Services

func (c *Context) Services() *app.Services

Services from current context

func (*Context) SetBaseURL

func (c *Context) SetBaseURL(baseURL string)

SetBaseURL on context

func (*Context) SetServices

func (c *Context) SetServices(services *app.Services)

SetServices on current context

func (*Context) SetTenant

func (c *Context) SetTenant(tenant *models.Tenant)

SetTenant on context

func (*Context) SetUser

func (c *Context) SetUser(user *models.User)

SetUser on context

func (*Context) TaskName

func (c *Context) TaskName() string

TaskName from current context

func (*Context) Tenant

func (c *Context) Tenant() *models.Tenant

Tenant from current context

func (*Context) User

func (c *Context) User() *models.User

User from current context

func (*Context) WorkerID

func (c *Context) WorkerID() string

WorkerID executing current context

type Job

type Job func(c *Context) error

Job is what's going to be run on background

type MiddlewareFunc

type MiddlewareFunc func(Job) Job

MiddlewareFunc is worker middleware

type Task

type Task struct {
	Name string
	Job  Job
}

Task represents the Name and Job to be run on background

type Worker

type Worker interface {
	Run(id string)
	Enqueue(task Task)
	Logger() log.Logger
	Use(middleware MiddlewareFunc)
	Length() int64
	Shutdown(ctx context.Context) error
}

Worker is a process that runs tasks

Jump to

Keyboard shortcuts

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