Documentation ¶
Index ¶
- Constants
- Variables
- func MemInfo(job *Job) ([]byte, error)
- func SysInfo(job *Job) ([]byte, error)
- type Job
- type JobFunc
- type JobFuncs
- type JobHandler
- type Worker
- func (worker *Worker) AddFunc(funcname string, f JobFunc, timeout uint32) (err error)
- func (worker *Worker) AddServer(addr string) (err error)
- func (worker *Worker) Close()
- func (worker *Worker) Echo(data []byte)
- func (worker *Worker) RemoveFunc(funcname string) (err error)
- func (worker *Worker) Reset()
- func (worker *Worker) SetId(id string)
- func (worker *Worker) Work()
Constants ¶
const ( Unlimited = 0 OneByOne = 1 Immediately = 0 )
Variables ¶
var (
ErrConnection = common.ErrConnection
)
Functions ¶
Types ¶
type Job ¶
type Job struct { Data []byte Handle, UniqueId, Fn string DataType uint32 // contains filtered or unexported fields }
Worker side job
func (*Job) UpdateData ¶
Send some datas to client. Using this in a job's executing.
func (*Job) UpdateStatus ¶
Update status. Tall client how many percent job has been executed.
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 (*Worker) AddFunc ¶
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 ¶
Add a server. The addr should be 'host:port' format. The connection is established at this time.
func (*Worker) RemoveFunc ¶
Remove a function. Tell job servers 'I can not do this now' at the same time.