-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync core-lro v3-beta to main branch (#29311)
Sync core-lro v3-beta to main branch: - api view: [diff compared with v3](https://apiview.dev/Assemblies/Review/2c2e6c39be9f4efcb7dcb5812ec03caa?revisionId=024991bbcc9e4f10ac52b484d6ff3267&diffRevisionId=c2c407f93624426090afa05dfb58d7c1#@azure/core-lro!CreateHttpPollerOptions:interface) - migration guide: [here](https://github.com/Azure/azure-sdk-for-js/pull/29311/files?short_path=149185f#diff-149185f78f3ba6e8a607806071880f4954bae228de2fd7a63965abbc85c869ce) - design doc: [loop 1](https://microsoft.sharepoint.com/:fl:/s/61554b56-c90b-4961-ba7c-61caae235335/ERp0F2QPyX9ElPkeL2U5pioB7_ar6uwHWYiTa7roChsHVw?e=FcS0YL&nav=cz0lMkZzaXRlcyUyRjYxNTU0YjU2LWM5MGItNDk2MS1iYTdjLTYxY2FhZTIzNTMzNSZkPWIhWkhjMnhhbl9nVXVNc3RET0NHaTNKMjZEQ09nVk5FRkxtTDg4UUNsZUpwaklYajhzTWlFSFRZVC02bTRGV2JkNSZmPTAxREdGMk9FWTJPUUxXSUQ2SlA1Q0pKNkk2RjVTVFRKUksmYz0lMkYmZmx1aWQ9MSZhPUxvb3BBcHAmcD0lNDBmbHVpZHglMkZsb29wLXBhZ2UtY29udGFpbmVyJng9JTdCJTIydyUyMiUzQSUyMlQwUlRVSHh0YVdOeWIzTnZablF1YzJoaGNtVndiMmx1ZEM1amIyMThZaUZhU0dNeWVHRnVYMmRWZFUxemRFUlBRMGRwTTBveU5rUkRUMmRXVGtWR1RHMU1PRGhSUTJ4bFNuQnFTVmhxT0hOTmFVVklWRmxVTFRadE5FWlhZbVExZkRBeFJFZEdNazlGTkZSRlRWRTBOMUpHUVRkYVJUSlBSazVEUkRSV1dEWTBNa1UlM0QlMjIlMkMlMjJpJTIyJTNBJTIyYjA3OTYyZWQtMWM4Ni00Zjg3LWE3OTctYjE0MDg1ZmEwYzY4JTIyJTdE), [loop 2](https://microsoft.sharepoint.com/:fl:/s/61554b56-c90b-4961-ba7c-61caae235335/EdO7c7zhNQ5PouqkX5YbPZ4BXAnvlDCvW9SiARuN8gMcww?e=LufGPM&nav=cz0lMkZzaXRlcyUyRjYxNTU0YjU2LWM5MGItNDk2MS1iYTdjLTYxY2FhZTIzNTMzNSZkPWIhWkhjMnhhbl9nVXVNc3RET0NHaTNKMjZEQ09nVk5FRkxtTDg4UUNsZUpwaklYajhzTWlFSFRZVC02bTRGV2JkNSZmPTAxREdGMk9FNlRYTlozWllKVkJaSDJGMlZFTDZMQldQTTYmYz0lMkYmZmx1aWQ9MSZhPUxvb3BBcHAmcD0lNDBmbHVpZHglMkZsb29wLXBhZ2UtY29udGFpbmVyJng9JTdCJTIydyUyMiUzQSUyMlQwUlRVSHh0YVdOeWIzTnZablF1YzJoaGNtVndiMmx1ZEM1amIyMThZaUZhU0dNeWVHRnVYMmRWZFUxemRFUlBRMGRwTTBveU5rUkRUMmRXVGtWR1RHMU1PRGhSUTJ4bFNuQnFTVmhxT0hOTmFVVklWRmxVTFRadE5FWlhZbVExZkRBeFJFZEdNazlGTkZSRlRWRTBOMUpHUVRkYVJUSlBSazVEUkRSV1dEWTBNa1UlM0QlMjIlMkMlMjJpJTIyJTNBJTIyYjA3OTYyZWQtMWM4Ni00Zjg3LWE3OTctYjE0MDg1ZmEwYzVjJTIyJTdE) Impacted SDKs: - Currently I think no SDKs would be impacted. - Existing HLC SDKs would use v2, no impact; - RLC LRO wrapped its interface with v3 and without any breakings([see pr detail](Azure/autorest.typescript#2443)), no impact; - Modular would use v3. The only modular SDK that is OpenAI without LRO operations, so no impact. - In future there would be breaking when migrating HLC to Modular. Main changes: ```diff - export function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro: LongRunningOperation, options?: CreateHttpPollerOptions<TResult, TState>): Promise<SimplePollerLike<TState, TResult>>; + export function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro: RunningOperation, options?: CreateHttpPollerOptions<TResult, TState>): PollerLike<TState, TResult>; - export interface SimplePollerLike<TState extends OperationState<TResult>, TResult> { + export interface PollerLike<TState extends OperationState<TResult>, TResult> extends Promise<TResult> { - getOperationState(): TState; + readonly operationState: TState | undefined; - getResult(): TResult | undefined; + readonly result: TResult | undefined; - isDone(): boolean; + readonly isDone: boolean; - isStopped(): boolean; - stopPolling(): void; - toString(): string; + serialize(): Promise<string>; + submitted(): Promise<void>; onProgress(callback: (state: TState) => void): CancelOnProgress; poll(options?: { abortSignal?: AbortSignalLike; - }): Promise<void>; + }): Promise<TState>; pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike; }): Promise<TResult>; } ``` The preview pr is merged here: #28213. --------- Co-authored-by: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>
- Loading branch information
1 parent
d67190a
commit f471cf0
Showing
23 changed files
with
1,391 additions
and
1,605 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Migration Guide | ||
|
||
This document shows the customers of v2 LRO (Long Running Operations) on how to migrate their code to use the v3 libraries. | ||
|
||
## Main difference between v2 and v3 | ||
|
||
In v2, you have to `await` the LRO to get this poller. But `await` doesn't give you the final result, it gives you the poller to track the operation's status. This has confused some users who thought `await` would give them the final result. | ||
|
||
To make things clearer and easier to understand, we've changed how this works in v3. Now, our poller interface blends the need to track long-running operations with the usual way of handling asynchronous programming. And this is the main difference between them. | ||
|
||
Except that the `LroEngine` is no longer supported and you could use `createHttpPoller` to create a poller instead. | ||
|
||
If you have an existing application that uses our v2 libaries and you're interested in updating your application to use the latest one, here are the things that you need to do for the migration: | ||
|
||
## Creation of Poller | ||
|
||
In v2 we have two implementations for LRO: `LroEngine` and `SimplePollerLike` with `createHttpPoller`. In v3 we deprecate the former and keep the `PollerLike` with `createHttpPoller` to build the poller. And the return type is changed from `SimplePollerLike` to `PollerLike`. The creation code would be changed as below. | ||
|
||
From | ||
|
||
```typescript | ||
const pollerSetting: LongRunningOperation<TResult> = { | ||
requestMethod: "{http-method}", | ||
requestPath: "{path}", | ||
sendInitialRequest: async () => { | ||
// your code to send initial request | ||
}, | ||
sendPollRequest: async (path) => { | ||
// your code to trigger polling request | ||
}, | ||
}; | ||
const httpPoller = await createHttpPoller(pollerSetting, options); | ||
``` | ||
|
||
To | ||
|
||
```typescript | ||
const pollerSetting: RunningOperation<TResult> = { | ||
sendInitialRequest: async () => { | ||
// your code to send initial request | ||
}, | ||
sendPollRequest: async (path) => { | ||
// your code to trigger polling request | ||
}, | ||
}; | ||
const httpPoller = createHttpPoller(pollerSetting, options); | ||
``` | ||
|
||
Now please notice if you `await` the helper you would get the final result. | ||
|
||
```typescript | ||
const result = await httpPoller; | ||
``` | ||
|
||
## Poller API | ||
|
||
Also the return type for `createHttpPoller` is renamed from `SimplePollerLike` to `PollerLike`.The following table compares `SimplePollerLike` and `PollerLike`: | ||
|
||
| operation | `SimplePollerLike` | `PollerLike` | | ||
| -------------------------------------------------------------------------- | --------------------- | ----------------- | | ||
| return final results | `pollUntilDone()` | `pollUntilDone()` | | ||
| poll | `poll()` | `poll()` | | ||
| access the current state after receiving the response of each poll request | `onProgress()` | `onProgress()` | | ||
| check whether the operation finished | `isDone()` | `isDone` | | ||
| stop polling | `stopPolling()` | N/A | | ||
| check if the polling stopped | `isStopped()` | N/A | | ||
| get the current operation state | `getOperationState()` | `operationState` | | ||
| access the final result | `getResult()` | `result` | | ||
| serialize the poller state | `toString()` | `serialize()` | | ||
| wait the poller submitted successfully | N/A | `submitted` | | ||
|
||
Please note the operation `getOperationState(): TState` is changed to attribute `operationState: TState | undefined`, so the value could be `undefined` if the poller is not initialized yet. | ||
|
||
```ts | ||
const status = poller.getOperationState().status; | ||
``` | ||
|
||
now | ||
|
||
```ts | ||
const status = poller?.operationState?.status; | ||
``` | ||
|
||
If you want to serialize a poller, use the `serialize` instead. | ||
|
||
```ts | ||
const serializeState = poller.toString(); | ||
``` | ||
|
||
now | ||
|
||
```ts | ||
const serializeState = await poller.serialize(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.