jobber

package module
v0.0.0-...-b2b474b Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2015 License: MIT Imports: 1 Imported by: 0

README

jobber

Used for batch processing.

##The situation Similar jobs can be handled together. Like can be used for batch methods from AWS SQS.

User can as simple as just add job to a place. Then a worker will take out the jobs in that place to handle. If there are two jobs, the worker will take out two. If there are three, the worker will take out three. But there may be a max number, like 10. If there are 20 jobs, the worker will take out 10 first, and start another loop.

##The features

  • Simple usage. User will define a worker function, then just add jobs.
  • Fast return. Because user just need to add jobs and no need to wait jobs done.
  • Single worker and it will be in a seperate goroutine.
  • Thread-safe.
  • Cache jobs in memory and retry the failed ones.

##Install & Update

go get -u github.com/LeeQY/jobber

##Usage

####Define the worker function:

func handleFunc(jobs []interface{}) bool {
	...
}

####Create a jobber

// pass in the function and max number.
jobber := New(handleFunc, 20)

####Just add job

jobber.AddJob(job)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandleFunc

type HandleFunc func(batch []interface{}) bool

Define the handle function.

batch is the passed-in jobs return true is the jobs are successfully handled.

type Jobber

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

func New

func New(f HandleFunc, maxNum int) *Jobber

Create a New jobber

f is the handle function maxNum is the max number of jobs handled once.

func (*Jobber) AddJob

func (j *Jobber) AddJob(v interface{})

Add one job.

func (*Jobber) AddJobs

func (j *Jobber) AddJobs(v []interface{})

Add jobs.

Jump to

Keyboard shortcuts

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