Skip to content

Commit ed911bd

Browse files
committed
Renames SimpleTask as FunctionTask
1 parent 55bbd04 commit ed911bd

7 files changed

Lines changed: 45 additions & 43 deletions

File tree

internal/test/workflow_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestEmptyWorkflow(t *testing.T) {
4444
u.AssertEquals(t, wflow.Start.GetNext(), wflow.End.GetId())
4545
}
4646

47-
// TestSimpleWorkflow creates a simple Workflow with one StartTask, two SimpleTask and one EndTask, executes it and gets the result.
47+
// TestSimpleWorkflow creates a simple Workflow with one StartTask, two FunctionTask and one EndTask, executes it and gets the result.
4848
func TestSimpleWorkflow(t *testing.T) {
4949
//workflow.BranchNumber = 0
5050

@@ -82,7 +82,7 @@ func TestSimpleWorkflow(t *testing.T) {
8282
nextNodeId := prevNode.GetNext()
8383
currentNode, _ = wflow.Find(nextNodeId)
8484
u.AssertEquals(t, prevNode.GetNext(), currentNode.GetId())
85-
u.AssertTrue(t, prevNode.(*workflow.SimpleTask).Func == f.Name)
85+
u.AssertTrue(t, prevNode.(*workflow.FunctionTask).Func == f.Name)
8686
}
8787
prevNode = currentNode
8888
}
@@ -130,8 +130,8 @@ func TestChoiceWorkflow(t *testing.T) {
130130
u.AssertTrue(t, foundS)
131131
u.AssertEquals(t, simple.GetNext(), wflow.End.GetId())
132132
}
133-
case *workflow.SimpleTask:
134-
u.AssertTrue(t, n.(*workflow.SimpleTask).Func == f.Name)
133+
case *workflow.FunctionTask:
134+
u.AssertTrue(t, n.(*workflow.FunctionTask).Func == f.Name)
135135
}
136136
}
137137
}
@@ -179,7 +179,7 @@ func TestChoiceWorkflow_BuiltWithNextBranch(t *testing.T) {
179179
_, foundS := wflow.Find(s)
180180
u.AssertTrue(t, foundS)
181181
}
182-
case *workflow.SimpleTask:
182+
case *workflow.FunctionTask:
183183
u.AssertTrue(t, node.Func == f.Name)
184184
}
185185
}
@@ -214,7 +214,7 @@ func TestWorkflowBuilder(t *testing.T) {
214214
// tasks := workflow.NewNodeSetFrom(workflow.Tasks)
215215
for _, n := range wflow.Tasks {
216216
switch node := n.(type) {
217-
case *workflow.SimpleTask:
217+
case *workflow.FunctionTask:
218218
u.AssertTrue(t, node.Func == f.Name)
219219
case *workflow.ChoiceTask:
220220
choice := node
@@ -223,8 +223,8 @@ func TestWorkflowBuilder(t *testing.T) {
223223
// specific for this test
224224
alt0, foundAlt0 := wflow.Find(choice.AlternativeNextTasks[0])
225225
alt1, foundAlt1 := wflow.Find(choice.AlternativeNextTasks[1])
226-
firstAlternative := alt0.(*workflow.SimpleTask)
227-
secondAlternative := alt1.(*workflow.SimpleTask)
226+
firstAlternative := alt0.(*workflow.FunctionTask)
227+
secondAlternative := alt1.(*workflow.FunctionTask)
228228

229229
u.AssertTrue(t, foundAlt0)
230230
u.AssertTrue(t, foundAlt1)

internal/workflow/asl.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func buildingLoop(sm *asl.StateMachine, nextState asl.State, nextStateName strin
3939
taskState := nextState.(*asl.TaskState)
4040
b, err := BuildFromTaskState(builder, taskState, nextStateName)
4141
if err != nil {
42-
return nil, fmt.Errorf("failed building SimpleTask from task state: %v", err)
42+
return nil, fmt.Errorf("failed building FunctionTask from task state: %v", err)
4343
}
4444
builder = b
4545
nextState, nextStateName, isTerminal = findNextOrTerminate(taskState, sm)
@@ -75,7 +75,7 @@ func buildingLoop(sm *asl.StateMachine, nextState asl.State, nextStateName strin
7575
waitState := nextState.(*asl.WaitState)
7676
b, err := BuildFromWaitState(builder, waitState, nextStateName)
7777
if err != nil {
78-
return nil, fmt.Errorf("failed building SimpleTask with function 'wait' from Wait state: %v", err)
78+
return nil, fmt.Errorf("failed building FunctionTask with function 'wait' from Wait state: %v", err)
7979
}
8080
builder = b
8181
nextState, nextStateName, isTerminal = findNextOrTerminate(waitState, sm)
@@ -97,7 +97,7 @@ func buildingLoop(sm *asl.StateMachine, nextState asl.State, nextStateName strin
9797
return builder.Build()
9898
}
9999

100-
// BuildFromTaskState adds a SimpleTask to the previous Node. The simple node will have id as specified by the name parameter
100+
// BuildFromTaskState adds a FunctionTask to the previous Node. The simple node will have id as specified by the name parameter
101101
func BuildFromTaskState(builder *Builder, t *asl.TaskState, name string) (*Builder, error) {
102102
f, found := function.GetFunction(t.Resource) // Could have been used t.GetResources()[0], but it is better to avoid the array dereference
103103
if !found {
@@ -327,7 +327,7 @@ func BuildFromMapState(builder *Builder, c *asl.MapState, name string) (*Builder
327327
// return builder, nil
328328
}
329329

330-
// BuildFromPassState adds a SimpleTask with an identity function
330+
// BuildFromPassState adds a FunctionTask with an identity function
331331
func BuildFromPassState(builder *Builder, p *asl.PassState, name string) (*Builder, error) {
332332
// TODO: implement me
333333
return builder, nil

internal/workflow/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (b *Builder) AddSimpleNode(f *function.Function) *Builder {
4646
return b
4747
}
4848

49-
simpleNode := NewSimpleTask(f.Name)
49+
simpleNode := NewFunctionTask(f.Name)
5050

5151
b.workflow.add(simpleNode)
5252
err := b.prevNode.SetNext(simpleNode)
@@ -68,7 +68,7 @@ func (b *Builder) AddSimpleNodeWithId(f *function.Function, id string) *Builder
6868
return b
6969
}
7070

71-
simpleNode := NewSimpleTask(f.Name)
71+
simpleNode := NewFunctionTask(f.Name)
7272
simpleNode.Id = TaskId(id)
7373

7474
b.workflow.add(simpleNode)
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ import (
1212
"github.com/serverledge-faas/serverledge/internal/scheduling"
1313
)
1414

15-
// SimpleTask is a Task that receives one input and sends one result
16-
type SimpleTask struct {
15+
// FunctionTask is a Task that receives one input and sends one result
16+
type FunctionTask struct {
1717
baseTask
1818
Func string
1919
}
2020

21-
func NewSimpleTask(f string) *SimpleTask {
22-
return &SimpleTask{
23-
baseTask: baseTask{Id: TaskId(shortuuid.New()), Type: Simple},
21+
func NewFunctionTask(f string) *FunctionTask {
22+
return &FunctionTask{
23+
baseTask: baseTask{Id: TaskId(shortuuid.New()), Type: Function},
2424
Func: f,
2525
}
2626
}
2727

28-
func (s *SimpleTask) SetNext(nextTask Task) error {
28+
func (s *FunctionTask) SetNext(nextTask Task) error {
2929
s.NextTask = nextTask.GetId()
3030
return nil
3131
}
3232

33-
func (s *SimpleTask) execute(progress *Progress, input *PartialData, r *Request) (*PartialData, *Progress, bool, error) {
33+
func (s *FunctionTask) execute(progress *Progress, input *PartialData, r *Request) (*PartialData, *Progress, bool, error) {
3434

3535
err := s.CheckInput(input.Data)
3636
if err != nil {
@@ -52,10 +52,10 @@ func (s *SimpleTask) execute(progress *Progress, input *PartialData, r *Request)
5252
return outputData, progress, true, nil
5353
}
5454

55-
func (s *SimpleTask) exec(compRequest *Request, params ...map[string]interface{}) (map[string]interface{}, error) {
55+
func (s *FunctionTask) exec(compRequest *Request, params ...map[string]interface{}) (map[string]interface{}, error) {
5656
funct, ok := function.GetFunction(s.Func)
5757
if !ok {
58-
return nil, fmt.Errorf("SimpleTask.function is null: you must initialize SimpleTask's function to execute it")
58+
return nil, fmt.Errorf("FunctionTask.function is null: you must initialize FunctionTask's function to execute it")
5959
}
6060

6161
// the rest of the code is similar to a single function execution
@@ -112,7 +112,7 @@ func (s *SimpleTask) exec(compRequest *Request, params ...map[string]interface{}
112112
return outputData, nil
113113
}
114114

115-
func (s *SimpleTask) CheckInput(input map[string]interface{}) error {
115+
func (s *FunctionTask) CheckInput(input map[string]interface{}) error {
116116
funct, exists := function.GetFunction(s.Func)
117117
if !exists {
118118
return fmt.Errorf("funtion %s doesn't exists", s.Func)
@@ -125,6 +125,6 @@ func (s *SimpleTask) CheckInput(input map[string]interface{}) error {
125125
return funct.Signature.CheckOrMatchInputs(input)
126126
}
127127

128-
func (s *SimpleTask) String() string {
129-
return fmt.Sprintf("[SimpleTask (%s) func %s()]->%v", s.Id, s.Func, s.NextTask)
128+
func (s *FunctionTask) String() string {
129+
return fmt.Sprintf("[FunctionTask (%s) func %s()]->%v", s.Id, s.Func, s.NextTask)
130130
}

internal/workflow/progress.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ func printStatus(s TaskStatus) string {
4444
type TaskType string
4545

4646
const (
47-
Start TaskType = "StartTask"
48-
End TaskType = "EndTask"
49-
Simple TaskType = "SimpleTask"
50-
Choice TaskType = "ChoiceTask"
51-
Fail TaskType = "Fail"
52-
Succeed TaskType = "SuccessTask"
53-
Pass TaskType = "PassTask"
54-
Wait TaskType = "WaitNode"
47+
Start TaskType = "StartTask"
48+
End TaskType = "EndTask"
49+
Function TaskType = "FunctionTask"
50+
Choice TaskType = "ChoiceTask"
51+
Fail TaskType = "Fail"
52+
Succeed TaskType = "SuccessTask"
53+
Pass TaskType = "PassTask"
54+
Wait TaskType = "WaitNode"
5555
)
5656

5757
func TaskFromType(nodeType TaskType) Task {
@@ -60,8 +60,8 @@ func TaskFromType(nodeType TaskType) Task {
6060
return &StartTask{}
6161
case End:
6262
return &EndTask{}
63-
case Simple:
64-
return &SimpleTask{}
63+
case Function:
64+
return &FunctionTask{}
6565
case Choice:
6666
return &ChoiceTask{}
6767
case Fail:
@@ -71,7 +71,7 @@ func TaskFromType(nodeType TaskType) Task {
7171
case Pass:
7272
return &PassTask{}
7373
default:
74-
return &SimpleTask{}
74+
return &FunctionTask{}
7575
}
7676
}
7777

@@ -81,8 +81,8 @@ func printType(t TaskType) string {
8181
return "Start"
8282
case End:
8383
return "End"
84-
case Simple:
85-
return "Simple"
84+
case Function:
85+
return "Function"
8686
case Choice:
8787
return "Choice"
8888
case Fail:

internal/workflow/start_task.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ func (s *StartTask) SetNext(nextTask Task) error {
2626

2727
func (s *StartTask) execute(progress *Progress, partialData *PartialData) (*PartialData, *Progress, bool, error) {
2828

29+
// TODO: move this logic into workflow "handleCompletion(output)"
2930
progress.Complete(s.GetId())
31+
3032
err := progress.AddReadyTask(s.GetNext())
3133
if err != nil {
3234
return nil, progress, false, err

internal/workflow/workflow.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (workflow *Workflow) Execute(r *Request, input *PartialData, progress *Prog
201201
}
202202

203203
switch task := n.(type) {
204-
case *SimpleTask:
204+
case *FunctionTask:
205205
output, progress, shouldContinue, err = task.execute(progress, input, r)
206206
case *ChoiceTask:
207207
output, progress, shouldContinue, err = task.execute(progress, input, r)
@@ -240,7 +240,7 @@ func (workflow *Workflow) GetUniqueFunctions() []string {
240240
allFunctionsMap := make(map[string]interface{})
241241
for _, task := range workflow.Tasks {
242242
switch n := task.(type) {
243-
case *SimpleTask:
243+
case *FunctionTask:
244244
allFunctionsMap[n.Func] = nil
245245
default:
246246
continue
@@ -654,8 +654,8 @@ func (workflow *Workflow) decodeTask(taskId string, value json.RawMessage) error
654654
workflow.Tasks[TaskId(taskId)] = task
655655
return nil
656656
}
657-
case Simple:
658-
task := &SimpleTask{}
657+
case Function:
658+
task := &FunctionTask{}
659659
err = json.Unmarshal(value, task)
660660
if err == nil && task.Id != "" && task.Func != "" {
661661
workflow.Tasks[TaskId(taskId)] = task

0 commit comments

Comments
 (0)