worker

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: AGPL-3.0 Imports: 10 Imported by: 28

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackgroundWorker

type BackgroundWorker struct {
	context.Context

	sync.RWMutex
	// 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) Run

func (w *BackgroundWorker) Run(workerID 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 {
	context.Context
	// contains filtered or unexported fields
}

Context holds references to services available for jobs

func NewContext

func NewContext(ctx context.Context, workerID string, task Task) *Context

NewContext creates a new context

func (*Context) Failure added in v0.12.0

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

Failure logs details of error

func (*Context) Set added in v0.18.1

func (c *Context) Set(key interface{}, val interface{})

Set saves data in the context.

func (*Context) TaskName

func (c *Context) TaskName() string

TaskName from current context

func (*Context) Tenant

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

Tenant from current context

func (*Context) User

func (c *Context) User() *entity.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 {
	OriginContext context.Context
	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)
	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