Skip to content

Commit b0d58b8

Browse files
committed
Refactoring run method
Signed-off-by: fjtirado <[email protected]>
2 parents 084e9d7 + 45bb41e commit b0d58b8

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

impl/task_runner_call_http.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2025 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package impl
216

317
import (

impl/task_runner_do.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewTaskRunner(taskName string, task model.Task, workflowDef *model.Workflow
3232
case *model.DoTask:
3333
return NewDoTaskRunner(t.Do, workflowDef)
3434
case *model.ForTask:
35-
return NewForTaskRunner(taskName, t)
35+
return NewForTaskRunner(taskName, t, workflowDef)
3636
case *model.CallHTTP:
3737
return NewCallHttpRunner(taskName, t)
3838
default:
@@ -172,7 +172,7 @@ func (d *DoTaskRunner) runTask(input interface{}, taskSupport TaskSupport, runne
172172
taskSupport.SetTaskName(taskName)
173173

174174
if task.Input != nil {
175-
if input, err = d.processTaskInput(task, input, taskSupport); err != nil {
175+
if input, err = d.processTaskInput(task, input, taskSupport, taskName); err != nil {
176176
return nil, err
177177
}
178178
}
@@ -184,62 +184,62 @@ func (d *DoTaskRunner) runTask(input interface{}, taskSupport TaskSupport, runne
184184

185185
taskSupport.SetTaskRawOutput(output)
186186

187-
if output, err = d.processTaskOutput(task, output, taskSupport); err != nil {
187+
if output, err = d.processTaskOutput(task, output, taskSupport, taskName); err != nil {
188188
return nil, err
189189
}
190190

191-
if err = d.processTaskExport(task, output, taskSupport); err != nil {
191+
if err = d.processTaskExport(task, output, taskSupport, taskName); err != nil {
192192
return nil, err
193193
}
194194

195195
return output, nil
196196
}
197197

198198
// processTaskInput processes task input validation and transformation.
199-
func (d *DoTaskRunner) processTaskInput(task *model.TaskBase, taskInput interface{}, taskSupport TaskSupport) (output interface{}, err error) {
199+
func (d *DoTaskRunner) processTaskInput(task *model.TaskBase, taskInput interface{}, taskSupport TaskSupport, taskName string) (output interface{}, err error) {
200200
if task.Input == nil {
201201
return taskInput, nil
202202
}
203203

204-
if err = validateSchema(taskInput, task.Input.Schema, d.GetTaskName()); err != nil {
204+
if err = validateSchema(taskInput, task.Input.Schema, taskName); err != nil {
205205
return nil, err
206206
}
207207

208-
if output, err = traverseAndEvaluate(task.Input.From, taskInput, d.GetTaskName(), taskSupport.GetContext()); err != nil {
208+
if output, err = traverseAndEvaluate(task.Input.From, taskInput, taskName, taskSupport.GetContext()); err != nil {
209209
return nil, err
210210
}
211211

212212
return output, nil
213213
}
214214

215215
// processTaskOutput processes task output validation and transformation.
216-
func (d *DoTaskRunner) processTaskOutput(task *model.TaskBase, taskOutput interface{}, taskSupport TaskSupport) (output interface{}, err error) {
216+
func (d *DoTaskRunner) processTaskOutput(task *model.TaskBase, taskOutput interface{}, taskSupport TaskSupport, taskName string) (output interface{}, err error) {
217217
if task.Output == nil {
218218
return taskOutput, nil
219219
}
220220

221-
if output, err = traverseAndEvaluate(task.Output.As, taskOutput, d.GetTaskName(), taskSupport.GetContext()); err != nil {
221+
if output, err = traverseAndEvaluate(task.Output.As, taskOutput, taskName, taskSupport.GetContext()); err != nil {
222222
return nil, err
223223
}
224224

225-
if err = validateSchema(output, task.Output.Schema, d.GetTaskName()); err != nil {
225+
if err = validateSchema(output, task.Output.Schema, taskName); err != nil {
226226
return nil, err
227227
}
228228

229229
return output, nil
230230
}
231231

232-
func (d *DoTaskRunner) processTaskExport(task *model.TaskBase, taskOutput interface{}, taskSupport TaskSupport) (err error) {
232+
func (d *DoTaskRunner) processTaskExport(task *model.TaskBase, taskOutput interface{}, taskSupport TaskSupport, taskName string) (err error) {
233233
if task.Export == nil {
234234
return nil
235235
}
236236

237-
output, err := traverseAndEvaluate(task.Export.As, taskOutput, d.GetTaskName(), taskSupport.GetContext())
237+
output, err := traverseAndEvaluate(task.Export.As, taskOutput, taskName, taskSupport.GetContext())
238238
if err != nil {
239239
return err
240240
}
241241

242-
if err = validateSchema(output, task.Export.Schema, d.GetTaskName()); err != nil {
242+
if err = validateSchema(output, task.Export.Schema, taskName); err != nil {
243243
return nil
244244
}
245245

impl/task_runner_for.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ const (
2828
forTaskDefaultAt = "$index"
2929
)
3030

31-
func NewForTaskRunner(taskName string, task *model.ForTask) (*ForTaskRunner, error) {
31+
func NewForTaskRunner(taskName string, task *model.ForTask, workflowDef *model.Workflow) (*ForTaskRunner, error) {
3232
if task == nil || task.Do == nil {
3333
return nil, model.NewErrValidation(fmt.Errorf("invalid For task %s", taskName), taskName)
3434
}
3535

36-
doRunner, err := NewDoTaskRunner(task.Do)
36+
doRunner, err := NewDoTaskRunner(task.Do, workflowDef)
3737
if err != nil {
3838
return nil, err
3939
}

0 commit comments

Comments
 (0)