How to use signal to pause and resume workflow ? #4503
Unanswered
lantian789
asked this question in
Q&A
Replies: 1 comment 8 replies
-
Key idea:
Sample code in Golang client: func samplePauseResumeWorkflow(ctx workflow.Context) error {
// Use a signal to modify a status variable to indicate whether or not it's paused
s := workflow.NewSelector(ctx)
paused := false
s.AddReceive(workflow.GetSignalChannel(ctx, "operation"), func(c workflow.Channel, ok bool) {
if ok{
c.Receive(ctx, &paused)
}
})
// Use `workflow.Go` to run a different goroutine(don't use native go to start, which would cause non-deterministic issues)
workflow.Go(ctx, func(ctx workflow.Context) {
for {
s.Select(ctx)
}
})
// Use `workflow.Await` to wait for the condition before executing any step you want to check
workflow.Await(ctx, func() bool {
return paused != true
})
workflow.ExecuteActivity(ctx, activityA)
workflow.Await(ctx, func() bool {
return paused != true
})
workflow.ExecuteActivity(ctx, activityB)
....
....
} |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
There is some sample code snippet of how to use signal in some relevant documentation:
It 's still very hard for me to know how to use this great feature to stop and resume the workflow, I really appreciate if someone could provide a complete demo code to help me master this wonderful technique. Thank you so much !
Beta Was this translation helpful? Give feedback.
All reactions