-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Key Vault Keys] LRO refactoring #11717
Merged
sadasant
merged 6 commits into
Azure:master
from
sadasant:keyvault-keys/lro-refactoring-11698
Nov 17, 2020
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1def43
[Key Vault Keys] LRO refactoring
sadasant 1363312
Removed the pollerClient
sadasant dfba0a4
returning this, addresses https://github.com/Azure/azure-sdk-for-js/p…
sadasant d159219
Merge remote-tracking branch 'Azure/master' into keyvault-keys/lro-re…
sadasant 576b470
linting and formatting
sadasant 5a97c40
KeyVaultKeyPollOperationOptions
sadasant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,55 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { delay, RequestOptionsBase } from "@azure/core-http"; | ||
import { Poller } from "@azure/core-lro"; | ||
import { DeleteKeyPollOperationState, makeDeleteKeyPollOperation } from "./operation"; | ||
import { DeletedKey, KeyClientInterface } from "../../keysModels"; | ||
|
||
export interface DeleteKeyPollerOptions { | ||
client: KeyClientInterface; | ||
name: string; | ||
requestOptions?: RequestOptionsBase; | ||
intervalInMs?: number; | ||
resumeFrom?: string; | ||
} | ||
import { DeleteKeyPollOperation, DeleteKeyPollOperationState } from "./operation"; | ||
import { DeletedKey } from "../../keysModels"; | ||
import { KeyVaultKeyPoller, KeyVaultKeyPollerOptions } from "../keyVaultKeyPoller"; | ||
|
||
/** | ||
* Class that deletes a poller that waits until a key finishes being deleted | ||
*/ | ||
export class DeleteKeyPoller extends Poller<DeleteKeyPollOperationState, DeletedKey> { | ||
/** | ||
* Defines how much time the poller is going to wait before making a new request to the service. | ||
* @memberof DeleteKeyPoller | ||
*/ | ||
public intervalInMs: number; | ||
|
||
constructor(options: DeleteKeyPollerOptions) { | ||
const { client, name, requestOptions, intervalInMs = 2000, resumeFrom } = options; | ||
export class DeleteKeyPoller extends KeyVaultKeyPoller<DeleteKeyPollOperationState, DeletedKey> { | ||
constructor(options: KeyVaultKeyPollerOptions) { | ||
const { vaultUrl, client, name, requestOptions, intervalInMs = 2000, resumeFrom } = options; | ||
|
||
let state: DeleteKeyPollOperationState | undefined; | ||
|
||
if (resumeFrom) { | ||
state = JSON.parse(resumeFrom).state; | ||
} | ||
|
||
const operation = makeDeleteKeyPollOperation({ | ||
...state, | ||
name, | ||
requestOptions, | ||
client | ||
}); | ||
const operation = new DeleteKeyPollOperation( | ||
{ | ||
...state, | ||
name | ||
}, | ||
vaultUrl, | ||
client, | ||
requestOptions | ||
); | ||
|
||
super(operation); | ||
|
||
this.intervalInMs = intervalInMs; | ||
} | ||
|
||
/** | ||
* The method used by the poller to wait before attempting to update its operation. | ||
* @memberof DeleteKeyPoller | ||
*/ | ||
async delay(): Promise<void> { | ||
return delay(this.intervalInMs); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern of managing the client seems pretty nice, and definitely less leaky than before. It feels like a good balance between ruthless abstraction and the levels of duplication that we had previously, but it doesn't seem like it's much less verbose than what we had before.
It still feels bizarre to me that we have this state machine model where
update
can return a different operation, but I can't think of anywhere that we use it. That API suggests to me that returning a different kind of operation should be the way that we make the pollers progress in state, but instead we just have monolithicupdate
functions that handle everything and thenreturn this
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand how this might be weird! I wonder if it would make sense to open an issue to have a discussion over time of how we could improve this in core-lro 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think we should consider if we want this to be stateless or not (no strong feelings from me) and either we lean fully into stateless (get rid of
this
) or we lean fully away from it (don't bother returningthis
, because caller already has a copy of us)