You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

46 lines
908 B

  1. package worker
  2. import (
  3. "encoding/json"
  4. "runtime"
  5. )
  6. // Job handler
  7. type JobHandler func(Job) error
  8. type JobFunc func(Job) ([]byte, error)
  9. // The definition of the callback function.
  10. type jobFunc struct {
  11. f JobFunc
  12. timeout uint32
  13. }
  14. // Map for added function.
  15. type jobFuncs map[string]*jobFunc
  16. type systemInfo struct {
  17. GOOS, GOARCH, GOROOT, Version string
  18. NumCPU, NumGoroutine int
  19. NumCgoCall int64
  20. }
  21. func SysInfo(job Job) ([]byte, error) {
  22. return json.Marshal(&systemInfo{
  23. GOOS: runtime.GOOS,
  24. GOARCH: runtime.GOARCH,
  25. GOROOT: runtime.GOROOT(),
  26. Version: runtime.Version(),
  27. NumCPU: runtime.NumCPU(),
  28. NumGoroutine: runtime.NumGoroutine(),
  29. NumCgoCall: runtime.NumCgoCall(),
  30. })
  31. }
  32. var memState runtime.MemStats
  33. func MemInfo(job Job) ([]byte, error) {
  34. runtime.ReadMemStats(&memState)
  35. return json.Marshal(&memState)
  36. }