SHARE
TWEET

Untitled

a guest Oct 17th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "context"
  5.     "flag"
  6.     "go.uber.org/zap"
  7.     "time"
  8.  
  9.     "github.com/pborman/uuid"
  10.     "github.com/uber-common/cadence-samples/cmd/samples/common"
  11.     "go.uber.org/cadence/client"
  12.     "go.uber.org/cadence/worker"
  13. )
  14.  
  15. // This needs to be done as part of a bootstrap step when the process starts.
  16. // The workers are supposed to be long running.
  17. func startWorkers(h *common.SampleHelper) {
  18.     workflowClient, err := h.Builder.BuildCadenceClient()
  19.     if err != nil {
  20.         h.Logger.Error("Failed to build cadence client.", zap.Error(err))
  21.         panic(err)
  22.     }
  23.     ctx := context.WithValue(context.Background(), CadenceClientKey, workflowClient)
  24.  
  25.     // Configure worker options.
  26.     workerOptions := worker.Options{
  27.         MetricsScope:              h.Scope,
  28.         Logger:                    h.Logger,
  29.         BackgroundActivityContext: ctx,
  30.     }
  31.  
  32.     h.StartWorkers(h.Config.DomainName, ApplicationName, workerOptions)
  33. }
  34.  
  35. func startWorkflow(h *common.SampleHelper) {
  36.     workflowOptions := client.StartWorkflowOptions{
  37.         ID:                              "searchAttributes_" + uuid.New(),
  38.         TaskList:                        ApplicationName,
  39.         ExecutionStartToCloseTimeout:    time.Minute,
  40.         DecisionTaskStartToCloseTimeout: time.Minute,
  41.         //SearchAttributes:                getSearchAttributesForStart(), // optional search attributes when start workflow
  42.     }
  43.     h.StartWorkflow(workflowOptions, SearchAttributesWorkflow)
  44. }
  45.  
  46. func getSearchAttributesForStart() map[string]interface{} {
  47.     return map[string]interface{}{
  48.         "CustomIntField": 1,
  49.     }
  50. }
  51.  
  52. func main() {
  53.     var mode string
  54.     flag.StringVar(&mode, "m", "trigger", "Mode is worker or trigger.")
  55.     flag.Parse()
  56.  
  57.     var h common.SampleHelper
  58.     h.SetupServiceConfig()
  59.  
  60.     switch mode {
  61.     case "worker":
  62.         startWorkers(&h)
  63.  
  64.         // The workers are supposed to be long running process that should not exit.
  65.         // Use select{} to block indefinitely for samples, you can quit by CMD+C.
  66.         select {}
  67.     case "trigger":
  68.         startWorkflow(&h)
  69.     }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top