workers

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 23 Imported by: 1

README

This repo is a friendly fork of https://github.com/jrallison/go-workers.

Documentation

Index

Constants

View Source
const (
	DEFAULT_MAX_RETRY = 25
	LAYOUT            = "2006-01-02 15:04:05 MST"
)
View Source
const (
	RETRY_KEY          = "goretry"
	SCHEDULED_JOBS_KEY = "schedule"
)
View Source
const MetricsNamespace string = "go_worker"
View Source
const (
	NanoSecondPrecision = 1000000000.0
)

Variables

View Source
var (
	TaskEnqueueMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: MetricsNamespace,
		Name:      "task_enqueue",
		Help:      "number of task enqueue, grouped by queue name",
	}, []string{"name"})

	TaskDequeueMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: MetricsNamespace,
		Name:      "task_dequeue",
		Help:      "number of task dequeue, grouped by queue name",
	}, []string{"name"})

	TaskProcessedMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: MetricsNamespace,
		Name:      "task_processed",
		Help:      "Total number of tasks processed.",
	}, []string{"name", "error"})
)
View Source
var Config *config

Functions

func BeforeStart

func BeforeStart(f func())

func Configure

func Configure(options map[string]string)

func DuringDrain

func DuringDrain(f func())

func Enqueue

func Enqueue(queue, class string, args interface{}) (string, error)

func EnqueueAt

func EnqueueAt(queue, class string, at time.Time, args interface{}) (string, error)

func EnqueueIn

func EnqueueIn(queue, class string, in float64, args interface{}) (string, error)

func EnqueueWithOptions

func EnqueueWithOptions(queue, class string, args interface{}, opts EnqueueOptions) (string, error)

func MetricsHandler added in v1.2.1

func MetricsHandler() http.Handler

func Process

func Process(queue string, job jobFunc, concurrency int, mids ...Action)

func Quit

func Quit()

func ResetManagers

func ResetManagers() error

func Run

func Run()

func Start

func Start()

func Stats

func Stats(w http.ResponseWriter, req *http.Request)

func StatsServer

func StatsServer(port int)

Types

type Action

type Action interface {
	Call(queue string, message *Msg, next func() bool) bool
}

type Args

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

func (Args) Equals

func (d Args) Equals(other interface{}) bool

func (Args) ToJson

func (d Args) ToJson() string

type EnqueueData

type EnqueueData struct {
	Queue      string      `json:"queue,omitempty"`
	Class      string      `json:"class"`
	Args       interface{} `json:"args"`
	Jid        string      `json:"jid"`
	EnqueuedAt float64     `json:"enqueued_at"`
	EnqueueOptions
}

type EnqueueOptions

type EnqueueOptions struct {
	RetryCount int     `json:"retry_count,omitempty"`
	Retry      bool    `json:"retry,omitempty"`
	At         float64 `json:"at,omitempty"`
	Policy     int     `json:"policy,omitempty"`
}

type Fetcher

type Fetcher interface {
	Queue() string
	Fetch()
	Acknowledge(*Msg)
	Ready() chan bool
	FinishedWork() chan bool
	Messages() chan *Msg
	Close()
	Closed() bool
}

func NewFetch

func NewFetch(queue string, messages chan *Msg, ready chan bool) Fetcher

type MiddlewareLogging

type MiddlewareLogging struct{}

func (*MiddlewareLogging) Call

func (l *MiddlewareLogging) Call(queue string, message *Msg, next func() bool) (acknowledge bool)

type MiddlewareRetry

type MiddlewareRetry struct{}

func (*MiddlewareRetry) Call

func (r *MiddlewareRetry) Call(queue string, message *Msg, next func() bool) (acknowledge bool)

type Middlewares

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

func NewMiddleware

func NewMiddleware(actions ...Action) *Middlewares

func (*Middlewares) Append

func (m *Middlewares) Append(action Action)

func (*Middlewares) Prepend

func (m *Middlewares) Prepend(action Action)

type Msg

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

func NewMsg

func NewMsg(content string) (*Msg, error)

func (*Msg) Args

func (m *Msg) Args() *Args

func (Msg) Equals

func (d Msg) Equals(other interface{}) bool

func (*Msg) Jid

func (m *Msg) Jid() string

func (*Msg) OriginalJson

func (m *Msg) OriginalJson() string

func (Msg) ToJson

func (d Msg) ToJson() string

type WorkersLogger

type WorkersLogger interface {
	Println(...interface{})
	Printf(string, ...interface{})
}
var Logger WorkersLogger = log.New(os.Stdout, "workers: ", log.Ldate|log.Lmicroseconds)

Jump to

Keyboard shortcuts

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