temporalio / sdk-java

Temporal Java SDK
https://temporal.io
Apache License 2.0
225 stars 147 forks source link

PollWorkflowTaskQueueResponse should be available for interception #1051

Open Spikhalskiy opened 2 years ago

Spikhalskiy commented 2 years ago

Is your feature request related to a problem? Please describe. PollWorkflowTaskQueueResponse has the information about the WorkflowTask and contains some pieces of information that may be needed for reporting/logging. Specifically, the most interesting one is PollWorkflowTaskQueueResponse#attempt that may be used to log workflows that can't progress for a long time.

Describe the solution you'd like PollWorkflowTaskQueueResponse or some parts of it should be made available to the user-configured handler/interceptor.

TBD. It also can become an input of a new method of WorkflowInboundInterceptor. TBD because currently all methods of Interceptors are extremely bound to the user code lifecycle and directly connected to events in the user code, while this method would be something that interceptors are not currently observed/expose.

Describe alternatives you've considered To solve the specific problem of reporting a workflow that doesn't progress because of a large number of failures, we can just hardcode logging in a manner that Server currently does: https://github.com/temporalio/temporal/blob/61b9b65744e455d4a85681b117e8315287911621/service/history/workflow/workflow_task_state_machine.go#L763 This solution is not flexible and doesn't move the extensibility of the SDK forward though.

Additional context Related to https://github.com/temporalio/temporal/issues/2526

cretz commented 2 years ago

Technically this can be done with a gRPC interceptor. My concern with putting in our interceptors is we won't get to change our polling mechanism without breaking it. If it's needed for reporting/logging, maybe just making the most recent task available for a getter is good enough?

If done via our interceptors, arguably pollWorkflowTaskQueue should be on the outbound interceptor (and an equivalent for activities). I had considered putting it on the client interceptors, but in some languages like TypeScript that is a bit more difficult since it's Core that makes the call.

Also, we might want a general cross-SDK issue at https://github.com/temporalio/sdk-features or at least a general cross-SDK discussion because TypeScript won't be able to do this as cleanly as Go/Java.