using the following sequential by id otherwise parallel strategy below, how would I go about canceling a job in a sequential queue?
either the current being worked on workflow job or another job waiting in the queue
I thought about another signal but that would only work on the currently running job, is there a way to request a signal waiting to be processed to be canceled?
below strategy discussed in the following topic: Go SDK - Sequential by ID otherwise in parallel - #5 by maxim
signalChan := workflow.GetSignalChannel(ctx, signalName)
for i := 0; i < CONTINUE_AS_NEW_FREQUENCY; i++ {
var signalVal string
signalChan.Receive(ctx, &signalVal)
workflow.GetLogger(ctx).Info("Received signal!", "signal", signalName, "value", signalVal)
// PROCESS SIGNAL
}
// Drain signal channel asynchronously to avoid signal loss
for {
var signalVal string
ok := signalChan.ReceiveAsync(&signalVal)
if !ok {
break;
}
workflow.GetLogger(ctx).Info("Received signal!", "signal", signalName, "value", signalVal)
// PROCESS SIGNAL
}
return workflow.NewContinueAsNewError(ctx, WorkflowFn)
Can you clarify what you mean by job here and what you’re trying to do?
Completing a workflow will essentially ignore remaining signals. You can choose to process signals or not. The example you are showing only has value in the advanced use case of continue-as-new. If you need to just complete a workflow, you don’t need to drain channels.
job, in this case, is the next signal, another iteration of the workflow essentially runs the workflow again with different input.
for each workflow id if they are the same they are queued by signals if I wanted to cancel one of these signals in a queue is there a way to do this?
There isn’t really a concept of “cancel” signal. You can definitely ignore signals in code if you don’t want to process them (which essentially what happens to the rest of the signals when you return from the workflow).
OK, that is what I thought might be the case, was hoping there was a way to terminate one of the signals. I will add a check, as a part of each activity to check if the job has been canceled, (goal is also to be able to cancel a job that is stuck in a retry loop, or prevent the job to be run at all)
Thanks for your assistance Chad.