mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-09 00:30:28 +00:00
Catch the panic and print the error (#305)
refactor # 215 Catch the panic and print the error close #215 Co-authored-by: CaiCandong <[email protected]> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/305 Co-authored-by: caicandong <[email protected]> Co-committed-by: caicandong <[email protected]>
This commit is contained in:
1 parent
1a7ec5f339
commit
a1bb3b56fd
1 file changed
+23
-11
+23
-11
@@ -6,6 +6,7 @@ package poll
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
||||||
@@ -45,19 +46,30 @@ func (p *Poller) Poll(ctx context.Context) {
|
|||||||
func (p *Poller) poll(ctx context.Context, wg *sync.WaitGroup, limiter *rate.Limiter) {
|
func (p *Poller) poll(ctx context.Context, wg *sync.WaitGroup, limiter *rate.Limiter) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for {
|
for {
|
||||||
if err := limiter.Wait(ctx); err != nil {
|
p.pollTaskWithRateLimit(ctx, limiter)
|
||||||
if ctx.Err() != nil {
|
}
|
||||||
log.WithError(err).Debug("limiter wait failed")
|
}
|
||||||
}
|
|
||||||
return
|
func (p *Poller) pollTaskWithRateLimit(ctx context.Context, limiter *rate.Limiter) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
err := fmt.Errorf("panic: %v", r)
|
||||||
|
log.WithError(err).Error("panic in pollTaskWithRateLimit")
|
||||||
}
|
}
|
||||||
task, ok := p.fetchTask(ctx)
|
}()
|
||||||
if !ok {
|
|
||||||
continue
|
if err := limiter.Wait(ctx); err != nil {
|
||||||
}
|
if ctx.Err() != nil {
|
||||||
if err := p.runner.Run(ctx, task); err != nil {
|
log.WithError(err).Debug("limiter wait failed")
|
||||||
log.WithError(err).Error("failed to run task")
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
task, ok := p.fetchTask(ctx)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := p.runner.Run(ctx, task); err != nil {
|
||||||
|
log.WithError(err).Error("failed to run task")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user