-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (63 loc) · 2.55 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"os"
"time"
log "github.com/sirupsen/logrus"
"github.com/conductor-sdk/conductor-go/sdk/model"
"github.com/conductor-sdk/conductor-go/sdk/workflow"
apiUtil "github.com/conductor-sdk/go-sdk-examples/internal/api"
workerUtil "github.com/conductor-sdk/go-sdk-examples/internal/worker"
workflowUtil "github.com/conductor-sdk/go-sdk-examples/internal/workflow"
)
func main() {
setupLogSettings()
workerUtil.StartWorkers()
wf := workflowUtil.CreateAndRegisterWorkflow()
log.Info("\n\nStarting a workflow synchronously")
startWorkflowSync(wf)
log.Info("\n\nStarting a workflow asynchronously")
startWorkflowAsync(wf)
log.Info("\n\nStarting a workflow with Dynamic Fork/Join")
dynWorkflow := workflowUtil.CreateAndRegisterDynamicForkWorkflow()
startWorkflowSync(dynWorkflow)
workflowUtil.StartWorkflowWithRequest()
}
func setupLogSettings() {
log.SetFormatter(&log.TextFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.InfoLevel)
log.Info("Finished setting up log settings")
}
func startWorkflowSync(wf *workflow.ConductorWorkflow) {
workflowInput := workflowUtil.NewWorkflowInput("userA")
workflowRun, err := wf.ExecuteWorkflowWithInput(workflowInput, "")
if err != nil {
panic("failed to execute sync workflow, err: " + fmt.Sprint(err))
}
log.Info()
log.Info("=======================================================================================")
log.Info("Workflow Execution Completed")
log.Info("Workflow Id: " + workflowRun.WorkflowId)
log.Info("Workflow Status: " + workflowRun.Status)
log.Info("Workflow Output: " + fmt.Sprint(workflowRun.Output))
log.Info("Workflow Execution Flow UI: " + apiUtil.GetWorkflowExecutionURL(workflowRun.WorkflowId))
log.Info("=======================================================================================")
if workflowRun.Status != string(model.CompletedWorkflow) {
panic("workflow not completed")
}
}
func startWorkflowAsync(wf *workflow.ConductorWorkflow) {
workflowInput := workflowUtil.NewWorkflowInput("userA")
workflowId, err := wf.StartWorkflowWithInput(workflowInput)
if err != nil {
panic("failed to start async workflow, err: " + fmt.Sprint(err))
}
time.Sleep(5 * time.Second)
log.Info()
log.Info("=======================================================================================")
log.Info("Workflow Execution Completed")
log.Info("Workflow Id: " + workflowId)
log.Info("Workflow Execution Flow UI: " + apiUtil.GetWorkflowExecutionURL(workflowId))
log.Info("=======================================================================================")
}