time out not work
This commit is contained in:
parent
a142bcff58
commit
a980bc5de2
@ -24,6 +24,7 @@ var (
|
|||||||
ErrFuncNotFound = errors.New("The function was not found.")
|
ErrFuncNotFound = errors.New("The function was not found.")
|
||||||
ErrConnection = errors.New("Connection error.")
|
ErrConnection = errors.New("Connection error.")
|
||||||
ErrNoActiveAgent = errors.New("No active agent.")
|
ErrNoActiveAgent = errors.New("No active agent.")
|
||||||
|
ErrExecTimeOut = errors.New("Executing time out.")
|
||||||
)
|
)
|
||||||
func DisablePanic() {recover()}
|
func DisablePanic() {recover()}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package worker
|
package worker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"bitbucket.org/mikespook/gearman-go/common"
|
"bitbucket.org/mikespook/gearman-go/common"
|
||||||
)
|
)
|
||||||
@ -238,6 +237,12 @@ func (worker *Worker) SetId(id string) {
|
|||||||
|
|
||||||
// Execute the job. And send back the result.
|
// Execute the job. And send back the result.
|
||||||
func (worker *Worker) exec(job *Job) (err error) {
|
func (worker *Worker) exec(job *Job) (err error) {
|
||||||
|
if worker.limit != nil {
|
||||||
|
<-worker.limit
|
||||||
|
defer func() {
|
||||||
|
worker.limit <- true
|
||||||
|
}()
|
||||||
|
}
|
||||||
var limit int
|
var limit int
|
||||||
if job.DataType == common.JOB_ASSIGN {
|
if job.DataType == common.JOB_ASSIGN {
|
||||||
limit = 3
|
limit = 3
|
||||||
@ -257,20 +262,7 @@ func (worker *Worker) exec(job *Job) (err error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return common.Errorf("The function does not exist: %s", funcname)
|
return common.Errorf("The function does not exist: %s", funcname)
|
||||||
}
|
}
|
||||||
var result []byte
|
result, err := f.f(job)
|
||||||
if worker.limit != nil {
|
|
||||||
select {
|
|
||||||
case <-worker.limit:
|
|
||||||
defer func() {
|
|
||||||
worker.limit <- true
|
|
||||||
}()
|
|
||||||
case <-time.After(time.Second * time.Duration(f.timeout)):
|
|
||||||
err = common.Errorf("The function was executed timeout: %s", funcname)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
result, err = f.f(job)
|
|
||||||
}
|
|
||||||
var datatype uint32
|
var datatype uint32
|
||||||
if err == nil {
|
if err == nil {
|
||||||
datatype = common.WORK_COMPLETE
|
datatype = common.WORK_COMPLETE
|
||||||
|
Loading…
Reference in New Issue
Block a user