-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core-lro] Set isCancelled when operation status is cancelled (#21893)
* [core-lro] Set isCancelled when status is cancelled * don't check for isCanceled in TA test * fix lint * address feedback and handle cancellation uniformly * address feedback * add tests * edit * revert behavioral change * Update sdk/textanalytics/ai-text-analytics/package.json Co-authored-by: Will Temple <witemple@microsoft.com>
- Loading branch information
1 parent
4c5b90b
commit 51f5be7
Showing
12 changed files
with
503 additions
and
270 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
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 |
---|---|---|
@@ -1,39 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { | ||
LroBody, | ||
LroResponse, | ||
LroStatus, | ||
RawResponse, | ||
failureStates, | ||
successStates, | ||
} from "./models"; | ||
import { isUnexpectedPollingResponse } from "./requestUtils"; | ||
|
||
function getProvisioningState(rawResponse: RawResponse): string { | ||
const { properties, provisioningState } = (rawResponse.body as LroBody) ?? {}; | ||
const state: string | undefined = properties?.provisioningState ?? provisioningState; | ||
return typeof state === "string" ? state.toLowerCase() : "succeeded"; | ||
} | ||
|
||
export function isBodyPollingDone(rawResponse: RawResponse): boolean { | ||
const state = getProvisioningState(rawResponse); | ||
if (isUnexpectedPollingResponse(rawResponse) || failureStates.includes(state)) { | ||
throw new Error(`The long running operation has failed. The provisioning state: ${state}.`); | ||
} | ||
return successStates.includes(state); | ||
} | ||
import { LroResponse, LroStatus } from "./models"; | ||
import { getProvisioningState, isCanceled, isPollingDone } from "./requestUtils"; | ||
import { PollOperationState } from "../pollOperation"; | ||
|
||
/** | ||
* Creates a polling strategy based on BodyPolling which uses the provisioning state | ||
* from the result to determine the current operation state | ||
*/ | ||
export function processBodyPollingOperationResult<TResult>( | ||
response: LroResponse<TResult> | ||
): LroStatus<TResult> { | ||
return { | ||
...response, | ||
done: isBodyPollingDone(response.rawResponse), | ||
export function processBodyPollingOperationResult< | ||
TResult, | ||
TState extends PollOperationState<TResult> | ||
>(state: TState): (response: LroResponse<TResult>) => LroStatus<TResult> { | ||
return (response: LroResponse<TResult>): LroStatus<TResult> => { | ||
const status = getProvisioningState(response.rawResponse); | ||
return { | ||
...response, | ||
done: | ||
isCanceled({ | ||
state, | ||
status, | ||
}) || | ||
isPollingDone({ | ||
rawResponse: response.rawResponse, | ||
status, | ||
}), | ||
}; | ||
}; | ||
} |
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
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
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.