goflow icon indicating copy to clipboard operation
goflow copied to clipboard

Server will panic if use "time.sleep()" in node func

Open yueju1609 opened this issue 2 years ago • 0 comments

package main

import ( "fmt" "time"

goflow "github.com/s8sg/goflow" flow "github.com/s8sg/goflow/flow" )

// Workload function func doSomething1(data []byte, option map[string][]string) ([]byte, error) { time.Sleep(10 * time.Second) fmt.Println(fmt.Sprintf("you said 1 %s", string(data))) return []byte(fmt.Sprintf("you said 1 "%s"", string(data))), nil }

func doSomething2(data []byte, option map[string][]string) ([]byte, error) { time.Sleep(10 * time.Second) fmt.Println(fmt.Sprintf("you said 2 %s", string(data))) return []byte(fmt.Sprintf("you said 2 "%s"", string(data))), nil }

func doSomething3(data []byte, option map[string][]string) ([]byte, error) { time.Sleep(10 * time.Second) fmt.Println(fmt.Sprintf("you said 3 %s", string(data))) return []byte(fmt.Sprintf("you said 3 "%s"", string(data))), nil }

// Define provide definition of the workflow func DefineWorkflow(workflow *flow.Workflow, context *flow.Context) error { dag := workflow.Dag() dag.Node("test1").Apply("test1", doSomething1) dag.Node("test2").Apply("test2", doSomething2) dag.Node("test3").Apply("test3", doSomething3) dag.Edge("test1", "test2") dag.Edge("test2", "test3") return nil }

func main() { fs := &goflow.FlowService{ Port: 8080, RedisURL: "localhost:6379", OpenTraceUrl: "localhost:5775", WorkerConcurrency: 5, } fs.Register("myflow", DefineWorkflow) fs.StartWorker() err := fs.Execute("myflow", &goflow.Request{ RequestId: "request1", Body: []byte{'a', 'a', 'a'}, }) fmt.Println(err) err = fs.Execute("myflow", &goflow.Request{ RequestId: "request2", Body: []byte{'b', 'b', 'b'}, }) fmt.Println(err) }

yueju1609 avatar May 19 '22 07:05 yueju1609