worker

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: GPL-3.0 Imports: 11 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 {
	sync.RWMutex
	// contains filtered or unexported fields
}

BackgroundWorker is a worker that runs tasks on background

func New

func New(db *dbx.Database, logger log.Logger) *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(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 {
	// contains filtered or unexported fields
}

Context holds references to services available for jobs

func NewContext

func NewContext(workerID string, task Task, db *dbx.Database, logger log.Logger) *Context

NewContext creates a new context

func (Context) BaseURL

func (c Context) BaseURL() string

BaseURL from current context

func (*Context) Database added in v0.14.0

func (c *Context) Database() *dbx.Database

Database 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) LogoURL added in v0.15.0

func (c Context) LogoURL() string

LogoURL return the full URL to the tenant-specific logo URL

func (*Context) Services

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

Services from current context

func (*Context) SetAssetsBaseURL added in v0.18.0

func (c *Context) SetAssetsBaseURL(assetsBaseURL string)

SetAssetsBaseURL on context

func (*Context) SetBaseURL

func (c *Context) SetBaseURL(baseURL string)

SetBaseURL on context

func (*Context) SetLogoURL added in v0.15.0

func (c *Context) SetLogoURL(logoURL string)

SetLogoURL 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) TenantAssetsURL added in v0.18.0

func (c Context) TenantAssetsURL(path string, a ...interface{}) string

TenantAssetsURL return the full URL to a tenant-specific static asset

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 {
	OriginSessionID string
	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