@@ -19,6 +19,7 @@ import (
1919 "github.com/obot-platform/obot/pkg/wait"
2020 apierrors "k8s.io/apimachinery/pkg/api/errors"
2121 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+ "k8s.io/apimachinery/pkg/runtime/schema"
2223 kclient "sigs.k8s.io/controller-runtime/pkg/client"
2324)
2425
@@ -48,19 +49,16 @@ func (t *TaskHandler) Abort(req api.Context) error {
4849}
4950
5051func (t * TaskHandler ) AbortFromScope (req api.Context ) error {
51- workflow , userThread , err := t .getTask (req )
52+ workflow , projectThread , err := t .getTask (req )
5253 if err != nil {
5354 return err
5455 }
5556
56- return t .abort (req , workflow , userThread .Name )
57+ return t .abort (req , workflow , projectThread .Name )
5758}
5859
5960func (t * TaskHandler ) abort (req api.Context , workflow * v1.Workflow , threadName string ) error {
6061 taskRunID := req .PathValue ("run_id" )
61- if taskRunID == "" {
62- taskRunID = editorWFE (req , workflow .Name )
63- }
6462
6563 wfe , err := wait .For (req .Context (), req .Storage , & v1.WorkflowExecution {
6664 ObjectMeta : metav1.ObjectMeta {
@@ -109,9 +107,6 @@ func (t *TaskHandler) EventsFromScope(req api.Context) error {
109107
110108func (t * TaskHandler ) streamEvents (req api.Context , workflow * v1.Workflow , threadName string ) error {
111109 taskRunID := req .PathValue ("run_id" )
112- if taskRunID == "" {
113- taskRunID = editorWFE (req , workflow .Name )
114- }
115110
116111 wfe , err := wait .For (req .Context (), req .Storage , & v1.WorkflowExecution {
117112 ObjectMeta : metav1.ObjectMeta {
@@ -149,10 +144,6 @@ func (t *TaskHandler) streamEvents(req api.Context, workflow *v1.Workflow, threa
149144 return req .WriteEvents (events )
150145}
151146
152- func editorWFE (req api.Context , workflowName string ) string {
153- return name .SafeHashConcatName (system .ThreadPrefix , workflowName , req .User .GetUID ())
154- }
155-
156147func (t * TaskHandler ) AbortRun (req api.Context ) error {
157148 var workflow v1.Workflow
158149 if err := req .Get (& workflow , req .PathValue ("id" )); err != nil {
@@ -177,10 +168,6 @@ func (t *TaskHandler) abortRun(req api.Context, workflow *v1.Workflow) error {
177168 runID = req .PathValue ("run_id" )
178169 )
179170
180- if runID == "editor" {
181- runID = editorWFE (req , workflow .Name )
182- }
183-
184171 if err := req .Get (& wfe , runID ); err != nil {
185172 return err
186173 }
@@ -197,15 +184,6 @@ func (t *TaskHandler) abortRun(req api.Context, workflow *v1.Workflow) error {
197184 return abortThread (req , & thread )
198185}
199186
200- func (t * TaskHandler ) GetRun (req api.Context ) error {
201- var workflow v1.Workflow
202- if err := req .Get (& workflow , req .PathValue ("id" )); err != nil {
203- return err
204- }
205-
206- return t .getRun (req , & workflow )
207- }
208-
209187func (t * TaskHandler ) GetRunFromScope (req api.Context ) error {
210188 workflow , _ , err := t .getTask (req )
211189 if err != nil {
@@ -220,9 +198,6 @@ func (t *TaskHandler) getRun(req api.Context, workflow *v1.Workflow) error {
220198 wfe v1.WorkflowExecution
221199 runID = req .PathValue ("run_id" )
222200 )
223- if runID == "editor" {
224- runID = editorWFE (req , workflow .Name )
225- }
226201 if err := req .Get (& wfe , runID ); err != nil {
227202 return err
228203 }
@@ -298,14 +273,10 @@ func (t *TaskHandler) listRuns(req api.Context, workflow *v1.Workflow, userThrea
298273 }
299274
300275 var (
301- result types.TaskRunList
302- editorWFE = editorWFE (req , workflow .Name )
276+ result types.TaskRunList
303277 )
304278
305279 for _ , wfe := range wfeList .Items {
306- if wfe .Name == editorWFE {
307- continue
308- }
309280 result .Items = append (result .Items , convertTaskRun (workflow , & wfe ))
310281 }
311282
@@ -322,16 +293,17 @@ func (t *TaskHandler) Run(req api.Context) error {
322293}
323294
324295func (t * TaskHandler ) RunFromScope (req api.Context ) error {
325- workflow , userThread , err := t .getTask (req )
296+ workflow , projectThread , err := t .getTask (req )
326297 if err != nil {
327298 return err
328299 }
329300
330- return t .run (req , workflow , userThread .Name )
301+ return t .run (req , workflow , projectThread .Name )
331302}
332303
333304func (t * TaskHandler ) run (req api.Context , workflow * v1.Workflow , threadName string ) error {
334- stepID := req .Request .URL .Query ().Get ("step" )
305+ stepID := req .PathValue ("step_id" )
306+ runID := req .PathValue ("run_id" )
335307
336308 input , err := req .Body ()
337309 if err != nil {
@@ -355,7 +327,7 @@ func (t *TaskHandler) run(req api.Context, workflow *v1.Workflow, threadName str
355327 return err
356328 }
357329 wfe = resp .WorkflowExecution
358- } else if stepID == "" {
330+ } else if stepID == "" || runID == "" {
359331 wfe = & v1.WorkflowExecution {
360332 ObjectMeta : metav1.ObjectMeta {
361333 GenerateName : system .WorkflowExecutionPrefix ,
@@ -365,6 +337,7 @@ func (t *TaskHandler) run(req api.Context, workflow *v1.Workflow, threadName str
365337 Input : string (input ),
366338 ThreadName : threadName ,
367339 WorkflowName : workflow .Name ,
340+ RunUntilStep : req .URL .Query ().Get ("stepID" ),
368341 RunName : getRunIDFromUser (req ),
369342 },
370343 }
@@ -373,7 +346,7 @@ func (t *TaskHandler) run(req api.Context, workflow *v1.Workflow, threadName str
373346 }
374347 } else {
375348 resp , err := t .invoker .Workflow (req .Context (), req .Storage , workflow , string (input ), invoke.WorkflowOptions {
376- WorkflowExecutionName : editorWFE ( req , workflow . Name ) ,
349+ WorkflowExecutionName : runID ,
377350 StepID : stepID ,
378351 })
379352 if err != nil {
@@ -864,9 +837,6 @@ func getThreadForScope(req api.Context) (*v1.Thread, error) {
864837 taskID := req .PathValue ("task_id" )
865838 runID := req .PathValue ("run_id" )
866839 if taskID != "" && runID != "" {
867- if runID == "editor" {
868- runID = editorWFE (req , taskID )
869- }
870840 var wfe v1.WorkflowExecution
871841 if err := req .Get (& wfe , runID ); err != nil {
872842 return nil , err
@@ -877,6 +847,11 @@ func getThreadForScope(req api.Context) (*v1.Thread, error) {
877847 if wfe .Spec .WorkflowName != taskID {
878848 return nil , types .NewErrNotFound ("task run not found" )
879849 }
850+ if wfe .Status .ThreadName == "" {
851+ return nil , apierrors .NewNotFound (schema.GroupResource {
852+ Resource : "runs" ,
853+ }, runID )
854+ }
880855 return thread , req .Get (thread , wfe .Status .ThreadName )
881856 }
882857
0 commit comments