azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

[QUERY] Design discussion on returning activation response for long-running API

Open weidongxu-microsoft opened this issue 9 months ago • 1 comments

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

weidongxu-microsoft avatar Apr 29 '24 03:04 weidongxu-microsoft

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kushagraThapar @pjohari-ms @TheovanKraay.

github-actions[bot] avatar Apr 29 '24 03:04 github-actions[bot]

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
}

srnagar avatar Jul 30 '24 19:07 srnagar