curlew

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 4 Imported by: 6

README

Curlew

Curlew is a job queue based on single machine memory.

Feature

  • Automatically scale the number of workers up or down.
  • Don't ensure the job execution order.

Usage

d, err := curlew.New()
if err != nil {
    return
}
j := curlew.NewJob()
j.Arg = 3
j.Fn = func(ctx context.Context, arg interface{}) error {
    fmt.Println("I'm done")
    return nil
}
d.SubmitAsync(j)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {
	MaxWorkerNum         int
	JobSize              int
	WorkerIdleTimeout    time.Duration
	MaxJobRunningTimeout time.Duration
	WorkerPool           chan *Worker
	// contains filtered or unexported fields
}

func New

func New(setters ...Setter) (*Dispatcher, error)

func (*Dispatcher) Add

func (d *Dispatcher) Add(w *Worker)

func (*Dispatcher) Remove

func (d *Dispatcher) Remove(w *Worker)

func (*Dispatcher) RunningWorkerNum

func (d *Dispatcher) RunningWorkerNum() int

func (*Dispatcher) SubmitAsync

func (d *Dispatcher) SubmitAsync(j *Job)

type Handle

type Handle func(ctx context.Context, arg interface{}) error

type Job

type Job struct {
	Fn  Handle
	Arg interface{}
}

func NewJob

func NewJob() *Job

type Monitor

type Monitor func(j *Job, err error)

type Setter

type Setter func(d *Dispatcher) error

Setter configures a Dispatcher.

func WithJobSize

func WithJobSize(size int) Setter

func WithMaxWorkerNum

func WithMaxWorkerNum(num int) Setter

WithMaxWorkerNum configures maximum number of workers in the pool.

func WithMonitor

func WithMonitor(monitor Monitor) Setter

func WithWorkerIdleTimeout

func WithWorkerIdleTimeout(t time.Duration) Setter

type Worker

type Worker struct {
	Jobs chan *Job
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(d *Dispatcher) *Worker

func (*Worker) LastBusyTime

func (w *Worker) LastBusyTime() time.Time

func (*Worker) Running

func (w *Worker) Running() bool

func (*Worker) SetLastBusyTime

func (w *Worker) SetLastBusyTime()

func (*Worker) SetRunning

func (w *Worker) SetRunning(b bool)

Jump to

Keyboard shortcuts

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