chore(runner): support update log and task

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu
2022-09-25 18:54:00 +08:00
committed by Jason Song
parent 20c3d85ba9
commit 82431d8e11
11 changed files with 489 additions and 375 deletions

View File

@ -7,6 +7,7 @@ import (
"gitea.com/gitea/act_runner/client"
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
"github.com/bufbuild/connect-go"
log "github.com/sirupsen/logrus"
)
@ -26,37 +27,31 @@ type Runner struct {
}
// Run runs the pipeline stage.
func (s *Runner) Run(ctx context.Context, stage *runnerv1.Stage) error {
func (s *Runner) Run(ctx context.Context, task *runnerv1.Task) error {
l := log.
WithField("stage.id", stage.Id).
WithField("stage.name", stage.Name)
WithField("task.id", task.Id)
l.Info("start running pipeline")
// update machine in stage
stage.Machine = s.Machine
data, err := s.Client.Detail(ctx, &runnerv1.DetailRequest{
Stage: stage,
})
task.Machine = s.Machine
data, err := s.Client.Detail(ctx, connect.NewRequest(&runnerv1.DetailRequest{
Task: task,
}))
if err != nil && err == ErrDataLock {
l.Info("stage accepted by another runner")
l.Info("task accepted by another runner")
return nil
}
if err != nil {
l.WithError(err).Error("cannot accept stage")
l.WithError(err).Error("cannot accept task")
return err
}
l = log.WithField("repo.id", data.Repo.Id).
WithField("repo.name", data.Repo.Name).
WithField("build.id", data.Build.Id).
WithField("build.name", data.Build.Name)
l.Info("task details fetched")
l.Info("stage details fetched")
return s.run(ctx, data)
return s.run(ctx, data.Msg.Task)
}
func (s *Runner) run(ctx context.Context, data *runnerv1.DetailResponse) error {
return NewTask(data.Build.Id, s.Client).Run(ctx, data)
func (s *Runner) run(ctx context.Context, task *runnerv1.Task) error {
return NewTask(task.Id, s.Client).Run(ctx, task)
}