I wrote an Activity to simulate a long-running task.
// workflow.ActivityOptions{
// ScheduleToCloseTimeout: time.Minute * 30,
// HeartbeatTimeout: time.Minute * 2,
// WaitForCancellation: true,
// })
func Activity(ctx context.Context) error {
for range time.Tick(time.Second) {
if err := ctx.Err(); err != nil {
return ctx.Err()
}
activity.RecordHeartbeat(ctx)
logger.Info("task is running")
}
return nil
}
After executing a Workflow that includes this Activity, the log continuously prints “task is running”. Then, after executing Cancel Workflow, the screen still prints messages until about 30 to 50 seconds later, when the task is finally cancelled.
Since I executed RecordHeartbeat every second, I expected it to be able to receive the cancellation in 1 second.