worker: github.com/vitalie/worker Index | Files

package worker

import "github.com/vitalie/worker"

Index

Package Files

beanstalk_queue.go envelope.go error.go helpers.go memory_queue.go middleware.go middleware_airbrake.go middleware_logger.go middleware_recovery.go pool.go pool_opts.go queue.go queue_service.go signal.go status_writer.go worker.go

Constants

const (
    BeanstalkHost = "localhost" // Beanstalk default host.
    BeanstalkPort = "11300"     // Beanstalk default port.
    BeanstalkTube = "default"   // Beanstalk default queue.
    BeanstalkPrio = 100         // Beanstalk default job priority.

)
const (
    DefaultWorkersCount = 10
)

Variables

var (
    BeanstalkTimeout time.Duration = 1 * time.Second // Beanstalk reserve timeout.
    BeanstalkTTR     time.Duration = 2 * DefaultTTR  // Beanstalk default TTR (time to run).
)
var (
    DefaultTTR time.Duration = 10 * time.Minute
)

func AirbreakStack Uses

func AirbreakStack(id int64, key, env string) []Handler

AirbrakeStack is used to configure default middleware using Airbrake error tracking service (middlewares: Airbreak, Logger).

func CommonStack Uses

func CommonStack() []Handler

CommonStack is used to configure default middleware that's common for most applications (middlewares: Recovery, Logger).

func NewError Uses

func NewError(msg string) error

func NewErrorFmt Uses

func NewErrorFmt(format string, args ...interface{}) error

func SetQueue Uses

func SetQueue(q Queue) func(*Pool)

SetQueue assigns a custom queue to worker pool.

func SetWorkers Uses

func SetWorkers(n int) func(*Pool)

SetWorkers configures the pool concurrency.

func StructType Uses

func StructType(v interface{}) (string, error)

type Airbrake Uses

type Airbrake struct {
    Logger    *log.Logger
    Airbrake  *gobrake.Notifier
    StackAll  bool
    StackSize int
}

func NewAirbrake Uses

func NewAirbrake(id int64, key, env string) *Airbrake

func (*Airbrake) Exec Uses

func (r *Airbrake) Exec(sw StatusWriter, fact string, args *Args, next JobRunner)

type Args Uses

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

func (Args) String Uses

func (d Args) String() string

type BeanstalkQueue Uses

type BeanstalkQueue struct {
    Host string        // Beanstalk host.
    Port string        // Beanstalk port.
    Name string        // Beanstalk tube name.
    Prio uint32        // Beanstalk priority.
    TTR  time.Duration // Beanstalk time to run.
    // contains filtered or unexported fields
}

BeanstalkQueue represents a Beanstalk queue.

func (*BeanstalkQueue) Delete Uses

func (q *BeanstalkQueue) Delete(m Message) error

Delete deletes a job from the queue.

func (*BeanstalkQueue) Get Uses

func (q *BeanstalkQueue) Get() (Message, error)

Get peeks a job from the queue.

func (*BeanstalkQueue) Put Uses

func (q *BeanstalkQueue) Put(j Job) error

Put puts the job in the queue.

func (*BeanstalkQueue) Reject Uses

func (q *BeanstalkQueue) Reject(m Message) error

Reject rejects the job marking it as failed.

func (*BeanstalkQueue) Size Uses

func (q *BeanstalkQueue) Size() (uint64, uint64, error)

Size returns the queue size, only ready jobs are returned.

type Envelope Uses

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

func NewEnvelope Uses

func NewEnvelope(body []byte) (*Envelope, error)

func (*Envelope) Args Uses

func (e *Envelope) Args() *Args

func (*Envelope) String Uses

func (e *Envelope) String() string

func (*Envelope) Type Uses

func (e *Envelope) Type() string

type Error Uses

type Error struct {
    Err       string
    IsTimeout bool
}

func (*Error) Error Uses

func (e *Error) Error() string

func (*Error) Temporary Uses

func (e *Error) Temporary() bool

func (*Error) Timeout Uses

func (e *Error) Timeout() bool

type Factory Uses

type Factory interface {
    Make(*Args) (Job, error)
}

type Handler Uses

type Handler interface {
    Exec(sw StatusWriter, fact string, args *Args, next JobRunner)
}

type HandlerFunc Uses

type HandlerFunc func(sw StatusWriter, fact string, args *Args, next JobRunner)

func (HandlerFunc) Exec Uses

func (h HandlerFunc) Exec(sw StatusWriter, fact string, args *Args, next JobRunner)

type Job Uses

type Job interface {
    Runner
    Factory
}

type JobRunner Uses

type JobRunner func(sw StatusWriter, fact string, args *Args)

type Logger Uses

type Logger struct {
    *log.Logger
}

func NewLogger Uses

func NewLogger() *Logger

func (*Logger) Exec Uses

func (l *Logger) Exec(sw StatusWriter, fact string, args *Args, next JobRunner)

type MemoryQueue Uses

type MemoryQueue struct {
    sync.Mutex
    // contains filtered or unexported fields
}

MemoryQueue represents an ordered queue, this queue is used mainly for unit tests.

func (*MemoryQueue) Delete Uses

func (q *MemoryQueue) Delete(msg Message) error

func (*MemoryQueue) Get Uses

func (q *MemoryQueue) Get() (Message, error)

func (*MemoryQueue) Put Uses

func (q *MemoryQueue) Put(j Job) error

func (*MemoryQueue) Reject Uses

func (q *MemoryQueue) Reject(msg Message) error

func (*MemoryQueue) Size Uses

func (q *MemoryQueue) Size() (uint64, uint64, error)

type Message Uses

type Message interface {
    Type() string
    Args() *Args
}

type Payload Uses

type Payload struct {
    Type string      `json:"type"`
    Args interface{} `json:"args"`
}

Payload represents a queue message payload.

type Pool Uses

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

Pool represents a pool of workers connected to a queue.

func NewPool Uses

func NewPool(opts ...func(*Pool)) *Pool

NewPool returns a new Pool instance.

func (*Pool) Add Uses

func (p *Pool) Add(f Factory) error

Add registers a new job factory.

func (*Pool) Exec Uses

func (p *Pool) Exec(sw StatusWriter, fact string, args *Args)

Exec runs the job passing it through the middleware stack.

func (*Pool) Run Uses

func (p *Pool) Run(ctx context.Context) error

Run starts processing jobs from the queue.

func (*Pool) Use Uses

func (p *Pool) Use(h Handler)

Use appends a new middleware to current stack.

type Priority Uses

type Priority interface {
    Prio() uint32
}

type Queue Uses

type Queue interface {
    Put(Job) error
    Get() (Message, error)
    Delete(Message) error
    Reject(Message) error
    Size() (uint64, uint64, error)
}

func NewBeanstalkQueue Uses

func NewBeanstalkQueue(opts ...func(*BeanstalkQueue)) (Queue, error)

NewBeanstalkQueue returns a queue instance using custom options.

func NewMemoryQueue Uses

func NewMemoryQueue() Queue

type Recovery Uses

type Recovery struct {
    Logger    *log.Logger
    StackAll  bool
    StackSize int
}

func NewRecovery Uses

func NewRecovery() *Recovery

func (*Recovery) Exec Uses

func (r *Recovery) Exec(sw StatusWriter, fact string, args *Args, next JobRunner)

type Runner Uses

type Runner interface {
    Run() error
}

type StatusWriter Uses

type StatusWriter interface {
    Set(interface{})
    Get() error
    OK() bool
}

func NewStatusWriter Uses

func NewStatusWriter() StatusWriter

Package worker imports 17 packages (graph). Updated 2017-05-25. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).