mirror of
https://gitea.com/gitea/act_runner.git
synced 2025-02-06 18:04:45 +01:00
Catch the panic and print the error
This commit is contained in:
parent
1a7ec5f339
commit
44f0f2d3fb
@ -6,6 +6,7 @@ package poll
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
||||
@ -45,6 +46,18 @@ func (p *Poller) Poll(ctx context.Context) {
|
||||
func (p *Poller) poll(ctx context.Context, wg *sync.WaitGroup, limiter *rate.Limiter) {
|
||||
defer wg.Done()
|
||||
for {
|
||||
p.pollTaskWithRateLimit(ctx, limiter)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Poller) pollTaskWithRateLimit(ctx context.Context, limiter *rate.Limiter) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// we don't know whether log will panic, so just use fmt
|
||||
fmt.Printf("panic: %v\n", r)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := limiter.Wait(ctx); err != nil {
|
||||
if ctx.Err() != nil {
|
||||
log.WithError(err).Debug("limiter wait failed")
|
||||
@ -53,12 +66,11 @@ func (p *Poller) poll(ctx context.Context, wg *sync.WaitGroup, limiter *rate.Lim
|
||||
}
|
||||
task, ok := p.fetchTask(ctx)
|
||||
if !ok {
|
||||
continue
|
||||
return
|
||||
}
|
||||
if err := p.runner.Run(ctx, task); err != nil {
|
||||
log.WithError(err).Error("failed to run task")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Poller) fetchTask(ctx context.Context) (*runnerv1.Task, bool) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user