-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathquery_workflow.go
More file actions
34 lines (28 loc) · 968 Bytes
/
query_workflow.go
File metadata and controls
34 lines (28 loc) · 968 Bytes
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
package main
import (
"time"
"go.uber.org/cadence/workflow"
)
// ApplicationName is the task list for this sample
const ApplicationName = "queryGroup"
// queryWorkflow is an implementation of cadence workflow to demo how to setup query handler
func queryWorkflow(ctx workflow.Context) error {
queryResult := "started"
logger := workflow.GetLogger(ctx)
logger.Info("QueryWorkflow started")
// setup query handler for query type "state"
err := workflow.SetQueryHandler(ctx, "state", func(input []byte) (string, error) {
return queryResult, nil
})
if err != nil {
logger.Info("SetQueryHandler failed: " + err.Error())
return err
}
queryResult = "waiting on timer"
// to simulate workflow been blocked on something, in reality, workflow could wait on anything like activity, signal or timer
workflow.NewTimer(ctx, time.Minute*2).Get(ctx, nil)
logger.Info("Timer fired")
queryResult = "done"
logger.Info("QueryWorkflow completed")
return nil
}