Sometimes in my workflows I want to do a “throw-away” activity, meaning I want it to happen eventually if possible but I don’t care about the result and I don’t want to wait for it. An example could be firing off an email notification of something else the workflow has done. If the email takes a week to get sent, or never gets sent, I don’t want it to have any impact on the rest of the workflow because it is just a notification.
My pattern so far has been to start a new coroutine with workflow.Go
and using a context separate from the rest of the activities (e.g. it is not cancellable):
workflow.Go(ctx, func(ctx workflow.Context) {
emailContext := workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
StartToCloseTimeout: time.Minute,
RetryPolicy: &temporal.RetryPolicy{
MaximumInterval: time.Minute,
},
})
err := workflow.ExecuteActivity(emailContext, activities.SendEmail /* , params... */).Get(ctx, nil)
// Log error if any
}
Is there any downside to this approach? Is there another method that is better?
One issue I can think of is, what happens if the workflow finishes while the coroutine is still active?