gearman-go/worker/func.go

46 lines
908 B
Go
Raw Permalink Normal View History

2012-09-25 15:16:17 +08:00
package worker
import (
2013-08-30 12:36:57 +08:00
"encoding/json"
"runtime"
2012-09-25 15:16:17 +08:00
)
2013-08-30 18:01:10 +08:00
// Job handler
type JobHandler func(Job) error
type JobFunc func(Job) ([]byte, error)
// The definition of the callback function.
type jobFunc struct {
f JobFunc
timeout uint32
}
// Map for added function.
type jobFuncs map[string]*jobFunc
2013-08-30 18:01:10 +08:00
2012-09-25 15:16:17 +08:00
type systemInfo struct {
2013-08-30 12:36:57 +08:00
GOOS, GOARCH, GOROOT, Version string
NumCPU, NumGoroutine int
NumCgoCall int64
2012-09-25 15:16:17 +08:00
}
2013-08-30 18:01:10 +08:00
func SysInfo(job Job) ([]byte, error) {
2013-08-30 12:36:57 +08:00
return json.Marshal(&systemInfo{
GOOS: runtime.GOOS,
GOARCH: runtime.GOARCH,
GOROOT: runtime.GOROOT(),
Version: runtime.Version(),
NumCPU: runtime.NumCPU(),
NumGoroutine: runtime.NumGoroutine(),
NumCgoCall: runtime.NumCgoCall(),
})
2012-09-25 15:16:17 +08:00
}
var memState runtime.MemStats
2013-08-30 18:01:10 +08:00
func MemInfo(job Job) ([]byte, error) {
2013-08-30 12:36:57 +08:00
runtime.ReadMemStats(&memState)
return json.Marshal(&memState)
2012-09-25 15:16:17 +08:00
}