Commits

mikespook committed 84593af

Info funcs added

  • Participants
  • Parent commits c486ebd
  • Branches dev

Comments (0)

Files changed (3)

File example/py/client.py

     except Exception as e:
         print type(e)
 
+    try:
+        completed_job_request = client.submit_job("SysInfo", "")
+        check_request_status(completed_job_request)
+    except Exception as e:
+        print type(e)
+
+    try:
+        completed_job_request = client.submit_job("MemInfo", "")
+        check_request_status(completed_job_request)
+    except Exception as e:
+        print type(e)
+
 if __name__ == '__main__':
     main()
 

File example/worker.go

     w.AddFunc("ToUpper", ToUpper, worker.Immediately)
     w.AddFunc("ToUpperTimeOut5", ToUpperDelay10, 5)
     w.AddFunc("ToUpperTimeOut20", ToUpperDelay10, 20)
+    w.AddFunc("SysInfo", worker.SysInfo, worker.Immediately)
+    w.AddFunc("MemInfo", worker.MemInfo, worker.Immediately)
     go w.Work()
     sh := signal.NewHandler()
     sh.Bind(os.Interrupt, func() bool {return true})

File worker/func.go

+package worker
+
+import (
+    "runtime"
+    "encoding/json"
+)
+
+type systemInfo struct {
+    GOOS, GOARCH, GOROOT, Version string
+    NumCPU, NumGoroutine int
+    NumCgoCall int64
+}
+
+func SysInfo(job *Job) ([]byte, error) {
+    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(),
+    })
+}
+
+var memState runtime.MemStats
+
+func MemInfo(job *Job) ([]byte, error) {
+    runtime.ReadMemStats(&memState)
+    return json.Marshal(&memState)
+}