azure-sdk-for-java
azure-sdk-for-java copied to clipboard
[QUERY] Design discussion on returning activation response for long-running API
Query/Question Service is Face. Some API in it would return a response upon PUT/POST, which is useful for user, even before the LRO complete.
Our guideline would use SyncPoller
for the LRO, but the activation response is not accessible.
Possible design
None of them is / will be supported by emitter. So all involves customization in client.
One possible API response would be a model wrapping the ActivationResult
and the SyncPoller<PollResult, FinalResult>
. However this does not match the guideline.
Another problem is that the wrapper model would be different in async client, as it be Mono<ActivationResult>
+ PollerFlux<PollResult, FinalResult>
class SyncPollerContainer {
ActivationResult activationResult;
SyncPoller<PollResult, FinalResult> poller;
}
SyncPollerContainer beginOp();
Another possible API response would be a subclass of SyncPoller
which one additional API as e.g. getActivationResult()
. However, we cannot do this to the async client, as PollerFlux
class is final.
class SyncPollerContainer extends SyncPoller {
ActivationResult activationResult;
}
SyncPollerContainer beginOp();
One could leave out the LRO. The PUT/POST would not be framed as LRO, and just return e.g. Response<ActivationResult>
. But SDK provide some helper function to convert the response to SyncPoller<PollResult, FinalResult>
if user want to poll to completion.
Response<ActivationResult> opWithResponse();
Response<ActivationResult> response = opWithResponse();
SyncPoller<PollResult, FinalResult> poller = Helper.createPoller(response);
Setup (please complete the following information if applicable):
- OS: [e.g. iOS]
- IDE: [e.g. IntelliJ]
- Library/Libraries: [e.g. com.azure:azure-core:1.16.0 (groupId:artifactId:version)]
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [x] Query Added
- [ ] Setup information Added
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kushagraThapar @pjohari-ms @TheovanKraay.
Alternate option to consider:
// before
SyncPoller<PollResult, FinalResult> poller= client.beginOperation();
// after
SyncPoller<CustomResult, FinalResult> poller= client.beginOperation();
CustomResult customResult = poller.poll().getValue();
ActivationResult activationResult = customResult.getActivationResult();
CustomResult is a customized class that contains the activation result and the poll result.
public class CustomResult {
private ActivationResult activationResult;
private PollResult pollResult;
// getters and setters
}