worker

package
v0.0.0-...-aad241e Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2014 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unlimited = 0
	OneByOne  = 1

	Immediately = 0
)

Variables

View Source
var (
	ErrConnection = common.ErrConnection
)

Functions

func MemInfo

func MemInfo(job *Job) ([]byte, error)

func SysInfo

func SysInfo(job *Job) ([]byte, error)

Types

type Job

type Job struct {
	Data                 []byte
	Handle, UniqueId, Fn string

	DataType uint32
	// contains filtered or unexported fields
}

Worker side job

func (*Job) Canceled

func (job *Job) Canceled() <-chan bool

When a job was canceled, return a true form a channel

func (*Job) Close

func (job *Job) Close()

close the job

func (*Job) Encode

func (job *Job) Encode() (data []byte)

Encode a job to byte slice

func (*Job) UpdateData

func (job *Job) UpdateData(data []byte, iswarning bool)

Send some datas to client. Using this in a job's executing.

func (*Job) UpdateStatus

func (job *Job) UpdateStatus(numerator, denominator int)

Update status. Tall client how many percent job has been executed.

type JobFunc

type JobFunc func(*Job) ([]byte, error)

type JobFuncs

type JobFuncs map[string]*jobFunc

Map for added function.

type JobHandler

type JobHandler func(*Job) error

Job handler

type Worker

type Worker struct {
	Id string
	// assign a ErrFunc to handle errors
	ErrHandler common.ErrorHandler
	JobHandler JobHandler
	// contains filtered or unexported fields
}

Worker side api for gearman

usage: w = worker.New(worker.Unlimited) w.AddFunction("foobar", foobar) w.AddServer("127.0.0.1:4730") w.Work() // Enter the worker's main loop

The definition of the callback function 'foobar' should suit for the type 'JobFunction'. It looks like this:

func foobar(job *Job) (data []byte, err os.Error) {
    //sth. here
    //plaplapla...
    return
}

func New

func New(l int) (worker *Worker)

Get a new worker

func (*Worker) AddFunc

func (worker *Worker) AddFunc(funcname string,
	f JobFunc, timeout uint32) (err error)

Add a function. Plz added job servers first, then functions. The API will tell every connected job server that 'I can do this'

func (*Worker) AddServer

func (worker *Worker) AddServer(addr string) (err error)

Add a server. The addr should be 'host:port' format. The connection is established at this time.

func (*Worker) Close

func (worker *Worker) Close()

Close.

func (*Worker) Echo

func (worker *Worker) Echo(data []byte)

Send a something out, get the samething back.

func (*Worker) RemoveFunc

func (worker *Worker) RemoveFunc(funcname string) (err error)

Remove a function. Tell job servers 'I can not do this now' at the same time.

func (*Worker) Reset

func (worker *Worker) Reset()

Remove all of functions. Both from the worker or job servers.

func (*Worker) SetId

func (worker *Worker) SetId(id string)

Set the worker's unique id.

func (*Worker) Work

func (worker *Worker) Work()

Main loop

Jump to

Keyboard shortcuts

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