@@ -18,6 +18,8 @@ import (
18
18
"context"
19
19
"fmt"
20
20
21
+ "github.com/sirupsen/logrus"
22
+
21
23
"github.com/erda-project/erda/apistructs"
22
24
"github.com/erda-project/erda/modules/pipeline/dbclient"
23
25
"github.com/erda-project/erda/modules/pipeline/pipengine/actionexecutor/plugins/apitest/logic"
@@ -57,7 +59,41 @@ func (d *define) Create(ctx context.Context, task *spec.PipelineTask) (interface
57
59
}
58
60
59
61
func (d * define ) Start (ctx context.Context , task * spec.PipelineTask ) (interface {}, error ) {
60
- logic .Do (ctx , task )
62
+
63
+ go func (ctx context.Context , task * spec.PipelineTask ) {
64
+ executorDoneCh , ok := ctx .Value (spec .MakeTaskExecutorCtxKey (task )).(chan interface {})
65
+ if ! ok {
66
+ logrus .Warnf ("apitest: failed to get executor channel, pipelineID: %d, taskID: %d" , task .PipelineID , task .ID )
67
+ }
68
+
69
+ var status = apistructs .PipelineStatusFailed
70
+ defer func () {
71
+ if r := recover (); r != nil {
72
+ logrus .Errorf ("api-test logic do panic recover:%s" , r )
73
+ }
74
+ // if executor chan is nil, task framework can loop query meta get status
75
+ if executorDoneCh != nil {
76
+ executorDoneCh <- apistructs.PipelineStatusDesc {Status : status }
77
+ }
78
+ }()
79
+
80
+ logic .Do (ctx , task )
81
+
82
+ latestTask , err := d .dbClient .GetPipelineTask (task .ID )
83
+ if err != nil {
84
+ logrus .Errorf ("failed to query latest task, err: %v \n " , err )
85
+ return
86
+ }
87
+
88
+ meta := latestTask .Result .Metadata
89
+ for _ , metaField := range meta {
90
+ if metaField .Name == logic .MetaKeyResult {
91
+ if metaField .Value == logic .ResultSuccess {
92
+ status = apistructs .PipelineStatusSuccess
93
+ }
94
+ }
95
+ }
96
+ }(ctx , task )
61
97
return nil , nil
62
98
}
63
99
@@ -70,7 +106,7 @@ func (d *define) Status(ctx context.Context, task *spec.PipelineTask) (apistruct
70
106
if err != nil {
71
107
return apistructs.PipelineStatusDesc {}, fmt .Errorf ("failed to query latest task, err: %v" , err )
72
108
}
73
- * task = latestTask
109
+ // *task = latestTask
74
110
75
111
if task .Status .IsEndStatus () {
76
112
return apistructs.PipelineStatusDesc {Status : task .Status }, nil
@@ -92,12 +128,14 @@ func (d *define) Status(ctx context.Context, task *spec.PipelineTask) (apistruct
92
128
if metaField .Value == logic .ResultSuccess {
93
129
return apistructs.PipelineStatusDesc {Status : apistructs .PipelineStatusSuccess }, nil
94
130
}
95
- return apistructs.PipelineStatusDesc {Status : apistructs .PipelineStatusFailed }, nil
131
+ if metaField .Value == logic .ResultFailed {
132
+ return apistructs.PipelineStatusDesc {Status : apistructs .PipelineStatusFailed }, nil
133
+ }
96
134
}
97
135
}
98
136
99
137
// return created status to do start step
100
- return apistructs.PipelineStatusDesc {Status : apistructs .PipelineStatusCreated }, nil
138
+ return apistructs.PipelineStatusDesc {Status : apistructs .PipelineStatusRunning }, nil
101
139
}
102
140
103
141
func (d * define ) Inspect (ctx context.Context , task * spec.PipelineTask ) (apistructs.TaskInspect , error ) {
0 commit comments