1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

fix: report the job as failed when the [runner].timeout expires (#870)

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/870
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
This commit is contained in:
earl-warren 2025-08-16 20:45:24 +00:00
commit 1f7fa31b1a
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
8 changed files with 157 additions and 26 deletions

View file

@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
"code.forgejo.org/forgejo/runner/v9/internal/pkg/common"
"code.forgejo.org/forgejo/runner/v9/internal/pkg/config"
"code.forgejo.org/forgejo/runner/v9/internal/pkg/ver"
)
@ -45,7 +46,7 @@ func Execute(ctx context.Context) {
Use: "daemon",
Short: "Run as a runner daemon",
Args: cobra.MaximumNArgs(1),
RunE: runDaemon(ctx, &configFile),
RunE: runDaemon(common.WithDaemonContext(ctx, ctx), &configFile),
}
rootCmd.AddCommand(daemonCmd)

View file

@ -114,7 +114,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
}
}
poller := poll.New(cfg, cli, runner)
poller := poll.New(ctx, cfg, cli, runner)
go poller.Poll()

View file

@ -42,14 +42,14 @@ type poller struct {
done chan any
}
func New(cfg *config.Config, client client.Client, runner run.RunnerInterface) Poller {
return (&poller{}).init(cfg, client, runner)
func New(ctx context.Context, cfg *config.Config, client client.Client, runner run.RunnerInterface) Poller {
return (&poller{}).init(ctx, cfg, client, runner)
}
func (p *poller) init(cfg *config.Config, client client.Client, runner run.RunnerInterface) Poller {
pollingCtx, shutdownPolling := context.WithCancel(context.Background())
func (p *poller) init(ctx context.Context, cfg *config.Config, client client.Client, runner run.RunnerInterface) Poller {
pollingCtx, shutdownPolling := context.WithCancel(ctx)
jobsCtx, shutdownJobs := context.WithCancel(context.Background())
jobsCtx, shutdownJobs := context.WithCancel(ctx)
done := make(chan any)

View file

@ -118,7 +118,7 @@ func setTrace(t *testing.T) {
}
func TestPoller_New(t *testing.T) {
p := New(&config.Config{}, &mockClient{}, &mockRunner{})
p := New(t.Context(), &config.Config{}, &mockClient{}, &mockRunner{})
assert.NotNil(t, p)
}
@ -172,6 +172,7 @@ func TestPoller_Runner(t *testing.T) {
}
p := &mockPoller{}
p.init(
t.Context(),
&config.Config{
Runner: configRunner,
},
@ -239,6 +240,7 @@ func TestPoller_Fetch(t *testing.T) {
}
p := &mockPoller{}
p.init(
t.Context(),
&config.Config{
Runner: configRunner,
},

View file

@ -170,11 +170,7 @@ func (r *Runner) Run(ctx context.Context, task *runnerv1.Task) error {
reporter := report.NewReporter(ctx, cancel, r.client, task, r.cfg.Runner.ReportInterval)
var runErr error
defer func() {
lastWords := ""
if runErr != nil {
lastWords = runErr.Error()
}
_ = reporter.Close(lastWords)
_ = reporter.Close(runErr)
}()
reporter.RunDaemon()
runErr = r.run(ctx, task, reporter)