I’m trying to implement a logic that runs workflow sequentially. The only way i think about is using signals and SignalWithStartWorkflow
func (wf *Workflow) Do(ctx workflow.Context) error {
for {
signalChan := workflow.GetSignalChannel(ctx, SignalName)
var signal MySignal
signalChan.Receive(ctx, &signal)
workflow.ExecuteActivity(workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
ScheduleToCloseTimeout: time.Second * 10,
}), wf.Activity, signal.Id).Get(ctx, nil)
// ...
}
}
Looks like this is working implementation, but i fear about infinite for and event history
func (wf *Workflow) Do(ctx workflow.Context) error {
signalChan := workflow.GetSignalChannel(ctx, SignalName)
var signal MySignal
signalChan.Receive(ctx, &signal)
workflow.ExecuteActivity(workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
ScheduleToCloseTimeout: time.Second * 10,
}), wf.Activity, signal.Id).Get(ctx, nil)
return workflow.NewContinueAsNewError(ctx, wf.Do)
}
The implementation with continue-as-new doesn’t work correctly becase it loose some signals.
What is the best and correct way to implement sequentially running workflows?