mirror of https://code.forgejo.org/forgejo/runner
handle possible panic (#88)
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/88 Reviewed-by: Jason Song <i@wolfogre.com>pull/23/head
parent
63c1734bb5
commit
0d33f8f520
|
@ -54,24 +54,17 @@ func (p *Poller) Wait() {
|
|||
p.routineGroup.Wait()
|
||||
}
|
||||
|
||||
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
|
||||
func (p *Poller) handle(ctx context.Context, l *log.Entry) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
l.Errorf("handle task panic: %+v", r)
|
||||
}
|
||||
LOOP:
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
break LOOP
|
||||
return
|
||||
default:
|
||||
task, err := p.pollTask(ctx)
|
||||
if task == nil || err != nil {
|
||||
|
@ -90,10 +83,26 @@ func (p *Poller) Poll(ctx context.Context) 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)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Poller) pollTask(ctx context.Context) (*runnerv1.Task, error) {
|
||||
|
|
Loading…
Reference in New Issue