Skip to content

Commit

Permalink
chore: pool
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Jun 16, 2020
1 parent 9ed287c commit 52052b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/xiaojiaoyu100/curlew

go 1.12
go 1.14

require (
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
Expand Down
22 changes: 6 additions & 16 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,12 @@ func (w *Worker) schedule() {
select {
case j := <-w.Jobs:
{
done := make(chan struct{})
go func() {
defer func() {
w.d.WorkerPool <- w
done <- struct{}{}
if r := recover(); r != nil {
w.d.monitor(fmt.Errorf("job crash: job = %#v, err = %#v", 1, r))
}
}()
ctx, cancel := context.WithTimeout(context.TODO(), w.d.MaxJobRunningTimeout)
defer cancel()
if err := j.Fn(ctx, j.Arg); err != nil {
w.d.monitor(fmt.Errorf("job = %#v, err = %#v", j, err))
}
}()
<-done
ctx, cancel := context.WithTimeout(context.TODO(), w.d.MaxJobRunningTimeout)
if err := j.Fn(ctx, j.Arg); err != nil {
w.d.monitor(fmt.Errorf("job = %#v, err = %#v", j, err))
}
cancel()
w.d.WorkerPool <- w
}
}
}
Expand Down

0 comments on commit 52052b3

Please sign in to comment.