I have a couple of points I want to verify, and questions. They are mostly in the context of the Go client.
On the topic of human interaction, let’s say I need to capture a user’s details (e.g. through a signal), act on it (e.g. through an activity), and give a response to the user. Would the simplest option here be a signal, and query? And is it generally acceptable to query for structs rather than simple strings?
If I have a somewhat long-running activity that fails midway through because the VM running the worker shuts down, I’m guessing the activity will eventually fail assuming it has a timeout? And I can handle this case by setting a retry policy?
What’s the best way to handle a workflow timeout? For example, I want to carry out some compensation action if a workflow times out
The simplest is signal and then query. Temporal guarantees read after write consistency for this interaction. Yes, structs are supported as query results. This answer gives more options for implementing synchronous workflow updates.
Correct, the simplest way to retry it is by setting a retry policy.
Don’t rely on workflow timeout for any business logic as they are essentially “kill -9” on timer. Use timers inside the workflow for any business-related timeouts. In your case set a timer that performs cleanup when fired.
So that either the timeout kicks in or the activity completes.
If so, I suppose my next question is, what about error handling within the future? How does that get propagated back to the workflow? Would that be a matter of mutating some err, and checking for it?
I’m guessing the workflow will continue to run even after the Go routine finishes? And I can make it exit if the Go routine finishes by using a timer, and a channel:
Is there a similar example with the Java SDK? Specifically I’m wondering if there’s a way to create a newCancellationScope where the containing activities do not need to be invoked explicitly async.
It depends on your business logic. For example, you could pass a SettablePromise into syncBusinessLogic as a parameter and then wait on it during cleanup.
I see. I had hoped that CancellationScope.cancel would propagate the cancellation to any containing activities. Is there no way to achieve that behavior?
Oh I see, for long-running activities? I.e. similar to a Java thread checking its interrupted state, the activity would need to check if it’s been signaled for cancellation?
Would an activity in a waiting-to-retry state be automatically canceled via propagation?