mirror of
https://gitea.com/gitea/act_runner.git
synced 2024-12-29 04:17:09 +01:00
handle possible panic (#88)
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/88 Reviewed-by: Jason Song <i@wolfogre.com>
This commit is contained in:
parent
1596e4b1fd
commit
c8fad20f49
@ -57,24 +57,17 @@ func (p *Poller) Wait() {
|
|||||||
p.routineGroup.Wait()
|
p.routineGroup.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Poller) Poll(ctx context.Context) error {
|
func (p *Poller) handle(ctx context.Context, l *log.Entry) {
|
||||||
l := log.WithField("func", "Poll")
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
for {
|
l.Errorf("handle task panic: %+v", r)
|
||||||
// check worker number
|
|
||||||
p.schedule()
|
|
||||||
|
|
||||||
select {
|
|
||||||
// wait worker ready
|
|
||||||
case <-p.ready:
|
|
||||||
case <-ctx.Done():
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
LOOP:
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
break LOOP
|
return
|
||||||
default:
|
default:
|
||||||
task, err := p.pollTask(ctx)
|
task, err := p.pollTask(ctx)
|
||||||
if task == nil || err != nil {
|
if task == nil || err != nil {
|
||||||
@ -93,9 +86,25 @@ func (p *Poller) Poll(ctx context.Context) error {
|
|||||||
l.Errorf("execute task: %v", err.Error())
|
l.Errorf("execute task: %v", err.Error())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
break LOOP
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Poller) Poll(ctx context.Context) error {
|
||||||
|
l := log.WithField("func", "Poll")
|
||||||
|
|
||||||
|
for {
|
||||||
|
// check worker number
|
||||||
|
p.schedule()
|
||||||
|
|
||||||
|
select {
|
||||||
|
// wait worker ready
|
||||||
|
case <-p.ready:
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
p.handle(ctx, l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user