mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-06 17:40:58 +00:00
fix: use accessors on protobuf messages instead of struct members (#684)
So it does not panic if one is nil. Closes forgejo/runner#146 Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/684 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
90a12ccd80
commit
5e3cb5468c
8 changed files with 21 additions and 21 deletions
|
@ -156,7 +156,7 @@ func runCreateRunnerFile(ctx context.Context, args *createRunnerFileArgs, config
|
|||
return err
|
||||
} else {
|
||||
log.Infof("connection successful: %s, with version: %s, with labels: %v",
|
||||
resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels)
|
||||
resp.Msg.GetRunner().GetName(), resp.Msg.GetRunner().GetVersion(), resp.Msg.GetRunner().GetLabels())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -114,5 +114,5 @@ func Test_runCreateRunnerFile(t *testing.T) {
|
|||
)
|
||||
resp, err := cli.FetchTask(ctx, connect.NewRequest(&runnerv1.FetchTaskRequest{}))
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, resp.Msg.Task)
|
||||
assert.Nil(t, resp.Msg.GetTask())
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
|
|||
return err
|
||||
} else {
|
||||
log.Infof("runner: %s, with version: %s, with labels: %v, declared successfully",
|
||||
resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels)
|
||||
resp.Msg.GetRunner().GetName(), resp.Msg.GetRunner().GetVersion(), resp.Msg.GetRunner().GetLabels())
|
||||
// if declared successfully, override the labels in the.runner file with valid labels in the config file (if specified)
|
||||
runner.Update(ctx, ls)
|
||||
reg.Labels = ls.ToStrings()
|
||||
|
@ -119,14 +119,14 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
|
|||
go poller.Poll()
|
||||
|
||||
<-ctx.Done()
|
||||
log.Infof("runner: %s shutdown initiated, waiting [runner].shutdown_timeout=%s for running jobs to complete before shutting down", resp.Msg.Runner.Name, cfg.Runner.ShutdownTimeout)
|
||||
log.Infof("runner: %s shutdown initiated, waiting [runner].shutdown_timeout=%s for running jobs to complete before shutting down", resp.Msg.GetRunner().GetName(), cfg.Runner.ShutdownTimeout)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), cfg.Runner.ShutdownTimeout)
|
||||
defer cancel()
|
||||
|
||||
err = poller.Shutdown(ctx)
|
||||
if err != nil {
|
||||
log.Warnf("runner: %s cancelled in progress jobs during shutdown", resp.Msg.Runner.Name)
|
||||
log.Warnf("runner: %s cancelled in progress jobs during shutdown", resp.Msg.GetRunner().GetName())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ func runJob(ctx context.Context, configFile *string) func(cmd *cobra.Command, ar
|
|||
return err
|
||||
} else {
|
||||
log.Infof("runner: %s, with version: %s, with labels: %v, declared successfully",
|
||||
resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels)
|
||||
resp.Msg.GetRunner().GetName(), resp.Msg.GetRunner().GetVersion(), resp.Msg.GetRunner().GetLabels())
|
||||
// if declared successfully, override the labels in the.runner file with valid labels in the config file (if specified)
|
||||
runner.Update(ctx, ls)
|
||||
reg.Labels = ls.ToStrings()
|
||||
|
|
|
@ -343,10 +343,10 @@ func doRegister(ctx context.Context, cfg *config.Config, inputs *registerInputs)
|
|||
return err
|
||||
}
|
||||
|
||||
reg.ID = resp.Msg.Runner.Id
|
||||
reg.UUID = resp.Msg.Runner.Uuid
|
||||
reg.Name = resp.Msg.Runner.Name
|
||||
reg.Token = resp.Msg.Runner.Token
|
||||
reg.ID = resp.Msg.GetRunner().GetId()
|
||||
reg.UUID = resp.Msg.GetRunner().GetUuid()
|
||||
reg.Name = resp.Msg.GetRunner().GetName()
|
||||
reg.Token = resp.Msg.GetRunner().GetToken()
|
||||
|
||||
if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil {
|
||||
return fmt.Errorf("failed to save runner config: %w", err)
|
||||
|
|
|
@ -80,15 +80,15 @@ func (j *Job) fetchTask(ctx context.Context) (*runnerv1.Task, bool) {
|
|||
return nil, false
|
||||
}
|
||||
|
||||
if resp.Msg.TasksVersion > v {
|
||||
j.tasksVersion.CompareAndSwap(v, resp.Msg.TasksVersion)
|
||||
if resp.Msg.GetTasksVersion() > v {
|
||||
j.tasksVersion.CompareAndSwap(v, resp.Msg.GetTasksVersion())
|
||||
}
|
||||
|
||||
if resp.Msg.Task == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
j.tasksVersion.CompareAndSwap(resp.Msg.TasksVersion, 0)
|
||||
j.tasksVersion.CompareAndSwap(resp.Msg.GetTasksVersion(), 0)
|
||||
|
||||
return resp.Msg.Task, true
|
||||
return resp.Msg.GetTask(), true
|
||||
}
|
||||
|
|
|
@ -152,8 +152,8 @@ func (p *poller) fetchTask(ctx context.Context) (*runnerv1.Task, bool) {
|
|||
return nil, false
|
||||
}
|
||||
|
||||
if resp.Msg.TasksVersion > v {
|
||||
p.tasksVersion.CompareAndSwap(v, resp.Msg.TasksVersion)
|
||||
if resp.Msg.GetTasksVersion() > v {
|
||||
p.tasksVersion.CompareAndSwap(v, resp.Msg.GetTasksVersion())
|
||||
}
|
||||
|
||||
if resp.Msg.Task == nil {
|
||||
|
@ -161,7 +161,7 @@ func (p *poller) fetchTask(ctx context.Context) (*runnerv1.Task, bool) {
|
|||
}
|
||||
|
||||
// got a task, set `tasksVersion` to zero to focre query db in next request.
|
||||
p.tasksVersion.CompareAndSwap(resp.Msg.TasksVersion, 0)
|
||||
p.tasksVersion.CompareAndSwap(resp.Msg.GetTasksVersion(), 0)
|
||||
|
||||
return resp.Msg.Task, true
|
||||
return resp.Msg.GetTask(), true
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ func (r *Reporter) ReportLog(noMore bool) error {
|
|||
return err
|
||||
}
|
||||
|
||||
ack := int(resp.Msg.AckIndex)
|
||||
ack := int(resp.Msg.GetAckIndex())
|
||||
if ack < r.logOffset {
|
||||
return fmt.Errorf("submitted logs are lost %d < %d", ack, r.logOffset)
|
||||
}
|
||||
|
@ -356,11 +356,11 @@ func (r *Reporter) ReportState() error {
|
|||
return err
|
||||
}
|
||||
|
||||
for _, k := range resp.Msg.SentOutputs {
|
||||
for _, k := range resp.Msg.GetSentOutputs() {
|
||||
r.outputs.Store(k, struct{}{})
|
||||
}
|
||||
|
||||
if resp.Msg.State != nil && resp.Msg.State.Result == runnerv1.Result_RESULT_CANCELLED {
|
||||
if resp.Msg.GetState().GetResult() == runnerv1.Result_RESULT_CANCELLED {
|
||||
r.cancel()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue