mirror of
https://gitea.com/gitea/act_runner.git
synced 2024-12-27 19:38:20 +01:00
refactor(task): execute single task with gRPC data
This commit is contained in:
parent
5051e4aebd
commit
20c3d85ba9
@ -76,7 +76,7 @@ func runRoot(ctx context.Context, task *runtime.Task) func(cmd *cobra.Command, a
|
|||||||
}
|
}
|
||||||
|
|
||||||
task.BuildID, _ = strconv.ParseInt(jobID, 10, 64)
|
task.BuildID, _ = strconv.ParseInt(jobID, 10, 64)
|
||||||
task.Run(ctx)
|
task.Run(ctx, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package runtime
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"gitea.com/gitea/act_runner/client"
|
"gitea.com/gitea/act_runner/client"
|
||||||
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
|
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
|
||||||
@ -59,18 +58,5 @@ func (s *Runner) Run(ctx context.Context, stage *runnerv1.Stage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Runner) run(ctx context.Context, data *runnerv1.DetailResponse) error {
|
func (s *Runner) run(ctx context.Context, data *runnerv1.DetailResponse) error {
|
||||||
_, exist := globalTaskMap.Load(data.Build.Id)
|
return NewTask(data.Build.Id, s.Client).Run(ctx, data)
|
||||||
if exist {
|
|
||||||
return fmt.Errorf("task %d already exists", data.Build.Id)
|
|
||||||
}
|
|
||||||
|
|
||||||
task := NewTask(data.Build.Id, s.Client)
|
|
||||||
|
|
||||||
// set task ve to global map
|
|
||||||
// when task is done or canceled, it will be removed from the map
|
|
||||||
globalTaskMap.Store(data.Build.Id, task)
|
|
||||||
|
|
||||||
go task.Run(ctx)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -216,18 +216,27 @@ func (t *Task) reportSuccess(ctx context.Context) {
|
|||||||
_ = t.client.UpdateStep(ctx, stepRequest)
|
_ = t.client.UpdateStep(ctx, stepRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) Run(ctx context.Context) {
|
func (t *Task) Run(ctx context.Context, data *runnerv1.DetailResponse) error {
|
||||||
|
_, exist := globalTaskMap.Load(data.Build.Id)
|
||||||
|
if exist {
|
||||||
|
return fmt.Errorf("task %d already exists", data.Build.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// set task ve to global map
|
||||||
|
// when task is done or canceled, it will be removed from the map
|
||||||
|
globalTaskMap.Store(data.Build.Id, t)
|
||||||
|
|
||||||
workflowsPath, err := getWorkflowsPath(t.Input.repoDirectory)
|
workflowsPath, err := getWorkflowsPath(t.Input.repoDirectory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.reportFailure(ctx, err)
|
t.reportFailure(ctx, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
t.log.Debugf("workflows path: %s", workflowsPath)
|
t.log.Debugf("workflows path: %s", workflowsPath)
|
||||||
|
|
||||||
planner, err := model.NewWorkflowPlanner(workflowsPath, false)
|
planner, err := model.NewWorkflowPlanner(workflowsPath, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.reportFailure(ctx, err)
|
t.reportFailure(ctx, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var eventName string
|
var eventName string
|
||||||
@ -260,7 +269,7 @@ func (t *Task) Run(ctx context.Context) {
|
|||||||
curDir, err := os.Getwd()
|
curDir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.reportFailure(ctx, err)
|
t.reportFailure(ctx, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// run the plan
|
// run the plan
|
||||||
@ -298,7 +307,7 @@ func (t *Task) Run(ctx context.Context) {
|
|||||||
r, err := runner.New(config)
|
r, err := runner.New(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.reportFailure(ctx, err)
|
t.reportFailure(ctx, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel := artifacts.Serve(ctx, input.artifactServerPath, input.artifactServerPort)
|
cancel := artifacts.Serve(ctx, input.artifactServerPath, input.artifactServerPort)
|
||||||
@ -318,8 +327,9 @@ func (t *Task) Run(ctx context.Context) {
|
|||||||
|
|
||||||
if err := executor(ctx); err != nil {
|
if err := executor(ctx); err != nil {
|
||||||
t.reportFailure(ctx, err)
|
t.reportFailure(ctx, err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.reportSuccess(ctx)
|
t.reportSuccess(ctx)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user