-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from DmitryNaumov/feature/support-storage-service
Add support for Storage service
- Loading branch information
Showing
9 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
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
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,67 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Grpc.Core; | ||
using Yandex.Cloud.Operation; | ||
|
||
namespace Yandex.Cloud; | ||
|
||
public static class SdkExtensions | ||
{ | ||
public static Task<Operation.Operation> WaitForCompletionAsync(this Sdk sdk, Operation.Operation operation, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return sdk.WaitForCompletionAsync(operation, TimeSpan.FromSeconds(1), cancellationToken); | ||
} | ||
|
||
public static async Task<Operation.Operation> WaitForCompletionAsync(this Sdk sdk, Operation.Operation operation, TimeSpan pollingInterval, CancellationToken cancellationToken = default) | ||
{ | ||
if (operation.Done) | ||
{ | ||
return operation; | ||
} | ||
|
||
var operationId = operation.Id; | ||
var retryableCount = 0; | ||
while (true) | ||
{ | ||
try | ||
{ | ||
operation = await sdk.Services.Operation.OperationService.GetAsync( | ||
new GetOperationRequest | ||
{ | ||
OperationId = operationId | ||
}, | ||
cancellationToken: cancellationToken); | ||
|
||
if (operation.Done) | ||
{ | ||
return operation; | ||
} | ||
} | ||
catch (RpcException ex) when(ex.StatusCode == StatusCode.NotFound) | ||
{ | ||
retryableCount++; | ||
if (retryableCount >= 3) | ||
{ | ||
throw; | ||
} | ||
} | ||
|
||
await Task.Delay(pollingInterval, cancellationToken); | ||
} | ||
} | ||
|
||
public static Task<Operation.Operation> WaitForCompletionAsync(this Operation.Operation operation, Sdk sdk, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return sdk.WaitForCompletionAsync(operation, TimeSpan.FromSeconds(1), cancellationToken); | ||
} | ||
|
||
public static async Task<Operation.Operation> WaitForCompletionAsync(this AsyncUnaryCall<Operation.Operation> call, Sdk sdk, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var operation = await call.ResponseAsync; | ||
return await sdk.WaitForCompletionAsync(operation, TimeSpan.FromSeconds(1), cancellationToken); | ||
} | ||
} |
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