forked from yuxh/gearman-go
		
	Info funcs added
--HG-- branch : dev
This commit is contained in:
		
							parent
							
								
									8c67ce0830
								
							
						
					
					
						commit
						05590bfb8c
					
				@ -32,6 +32,18 @@ def main():
 | 
			
		||||
    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()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -52,6 +52,8 @@ func main() {
 | 
			
		||||
    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})
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										31
									
								
								worker/func.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								worker/func.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
			
		||||
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)
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user