[REST Clients] Add lro poller helper#15898
[REST Clients] Add lro poller helper#15898joheredi merged 16 commits intoAzure:mainfrom joheredi:core-client-lro
Conversation
ellismg
left a comment
There was a problem hiding this comment.
Didn't look at the core engine stuff at all, but have some feedback about the interface, specifically around falsy paths. Love the direction this is heading, though and the resulting FarmBeats samples look really nice.
There was a problem hiding this comment.
Initially, I named it getPoller but when prototyping how this would be generated I decided to name it like this to avoid collisions, for example, this is how the generator would consume this to export getPoller
export function getPoller<TResult extends HttpResponse>(
client: FarmBeatsRestClient,
initialResponse: TResult
): PollerLike<PollOperationState<TResult>, TResult> {
return getLongRunningPoller(client, initialResponse);
}If this one is named getPoller as well we'd need an import alias. Not a big deal though, I'm happy to change it to getPoller I'll wait to get more opinions from @bterlson and @xirzec
There was a problem hiding this comment.
But why generating this wrapper? just to hide the pollerOptions? but again, why?
There was a problem hiding this comment.
Discussed offline. This wrapper is generated to pass additional info to the LRO engine that we can abstract from the user. For example, there are cases where the Swagger would define an LRO that needs FinalStateVia, we would set that in this wrapper. The end-user doesn't need to know about FinalStateVia, they would only care about the polling interval and also a state to resume the polling if they want. The other options are meant for internal use only. So this wrapper hides that from end users.
There was a problem hiding this comment.
I deleted getPoller so I think we can move this dep to devDependencies now unless you want to add getPoller back but I do not see the point for it after the simplified getLongRunningPoller.
There was a problem hiding this comment.
Discussed offline. Brought back getPoller, see comment above for details
There was a problem hiding this comment.
This is going to be customer-facing, so should it be setIntervalInMs to be consistent with what we have in Track 2 packages? I know our guidelines have them as intervalInMs but it looks like we wanted to adopt the convention of having a prefix verb so our packages now uses setIntervalInMs. @bterlson what do you think about this?
There was a problem hiding this comment.
Actually, code gen generates updateIntervalInMs: https://github.com/Azure/autorest.typescript/blob/357d655a4b8414490c90145aa98ea1130e691b05/test/integration/generated/lro/src/models/index.ts#L655.
deyaaeldeen
left a comment
There was a problem hiding this comment.
Looks great, I left one last comment about naming.
bterlson
left a comment
There was a problem hiding this comment.
Very cool, nice work! Had much fun playing with it 😁
Introducing
@azure-rest/core-client-lroNote: Everything undersrc/lroEngineis interim, the plan is for it to live under@azure/core-lroand that work is tracked by #15775. For the purpose of this PR you can skip the contents of that folder.This package exports
getLongRunningPollerwhich is designed to be consumed by the REST client code generator and re-expose, this allows the code generator add additional metadata about the long running operation that may be present in the Swagger definition.getLongRunningPollertakes:clientwhich will be used internally to poll for the stateinitialResponsewhich is the response after submitting the initial response to the long running operationpollerOptionswhich has some setting that users can set such asintervalInMsto set the wait time before polls andresumeFromwhich takes a serialized state to create a poller.-finalStateVia, this parameter is typically abstracted from the user and set by the generator taking the value ofx-ms-long-running-operationin the swagger if it exists.Sample usage by Generator:
Sample final user usage