SHARE
TWEET

Untitled

a guest Jun 25th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func SampleTimerWorkflow(ctx workflow.Context, timerDelay time.Duration) error
  2. {
  3.     logger := workflow.GetLogger(ctx)
  4.     resetCh := workflow.GetSignalChannel(ctx, "reset")
  5.  
  6.     timerFired := false
  7.     delay := timerDelay
  8.     for ;!timerFired; {
  9.         selector := workflow.NewSelector(ctx)
  10.  
  11.         logger.Sugar().Infof("Setting up a timer to fire after: %v", delay)
  12.         timerCancelCtx, cancelTimerHandler := workflow.WithCancel(ctx)
  13.         timerFuture := workflow.NewTimer(timerCancelCtx, delay)
  14.         selector.AddFuture(timerFuture, func(f workflow.Future) {
  15.             logger.Info("Timer Fired.")
  16.             timerFired = true
  17.         })
  18.  
  19.         selector.AddReceive(resetCh, func(c workflow.Channel, more bool) {
  20.             logger.Info("Reset signal received.")
  21.             logger.Info("Cancel outstanding timer.")
  22.             cancelTimerHandler()
  23.  
  24.             var t int
  25.             c.Receive(ctx, &t)
  26.             logger.Sugar().Infof("Reset delay: %v seconds", t)
  27.             delay = time.Second * time.Duration(t)
  28.         })
  29.  
  30.         logger.Info("Waiting for timer to fire.")
  31.         selector.Select(ctx)
  32.     }
  33.  
  34.     workflow.GetLogger(ctx).Info("Workflow completed.")
  35.     return nil
  36. }
  37.      
  38. cadence-cli --domain <domain> wf signal -w <workflow_id>  --name reset --input 10
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top