The worker component should support cancelation via GRPC method call on the wrapper interface. Remember, the wrapper interface delegates to operations inside the wrapped container.
Q: Go supports cancelation but in other languages how can you cancel running methods?
A: Spawn operations in a thread and then kill the thread? Must have a main thread that does not die in the container. A cancel will only cancel the child and be able to "recalled" without recreating the container.
This means the GRPC wrapper should support cancelation as well as delegation
Here is an example of cancelation:
func main() {
// Create a new context
ctx := context.Background()
// Create a new context, with its cancellation function
// from the original context
ctx, cancel := context.WithCancel(ctx)
// Run two operations: one in a different go routine
go func() {
err := operation1(ctx)
// If this operation returns an error
// cancel all operations using this context
if err != nil {
cancel()
}
}()
// Run operation2 with the same context we use for operation1
operation2(ctx)
}
https://www.sohamkamani.com/blog/golang/2018-06-17-golang-using-context-cancellation/
So at the top of the call chain, a context will be created, but - we need to be able to signal cancelation from outside the wrapper. The wrapper must be able to respond to cancel methods and in response use the context object created for the chain to cancel all running operations.
A retry should be implemented in the calling code. ie. If response is not received cancel existing and call again.
There should be some support specifying retry semantics in the DSL.
No comments:
Post a Comment