chore(runner): update fetch job request

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu
2022-09-29 22:19:21 +08:00
committed by Jason Song
parent 82431d8e11
commit 7486d2ab91
5 changed files with 17 additions and 38 deletions

View File

@ -2,23 +2,13 @@ package runtime
import (
"context"
"errors"
"gitea.com/gitea/act_runner/client"
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
"github.com/bufbuild/connect-go"
log "github.com/sirupsen/logrus"
)
var ErrDataLock = errors.New("Data Lock Error")
// Defines the Resource Kind and Type.
const (
Kind = "pipeline"
Type = "docker"
)
// Runner runs the pipeline.
type Runner struct {
Machine string
@ -30,28 +20,7 @@ type Runner struct {
func (s *Runner) Run(ctx context.Context, task *runnerv1.Task) error {
l := log.
WithField("task.id", task.Id)
l.Info("start running pipeline")
// update machine in stage
task.Machine = s.Machine
data, err := s.Client.Detail(ctx, connect.NewRequest(&runnerv1.DetailRequest{
Task: task,
}))
if err != nil && err == ErrDataLock {
l.Info("task accepted by another runner")
return nil
}
if err != nil {
l.WithError(err).Error("cannot accept task")
return err
}
l.Info("task details fetched")
return s.run(ctx, data.Msg.Task)
}
func (s *Runner) run(ctx context.Context, task *runnerv1.Task) error {
return NewTask(task.Id, s.Client).Run(ctx, task)
}