public static async Task <Operation> PollUntilCompletedAsync(this Operation operation, string projectId, string zone) { ZoneOperationsClient operationClient = await ZoneOperationsClient.CreateAsync(); GetZoneOperationRequest pollRequest = new GetZoneOperationRequest { Operation = operation.Name, Zone = zone, Project = projectId, }; TimeSpan timeOut = TimeSpan.FromMinutes(3); TimeSpan pollInterval = TimeSpan.FromSeconds(15); DateTime deadline = DateTime.UtcNow + timeOut; while (operation.Status != Operation.Types.Status.Done) { operation = await operationClient.GetAsync(pollRequest); if (operation.Status == Operation.Types.Status.Done) { break; } if (DateTime.UtcNow + pollInterval > deadline) { throw new InvalidOperationException("Timeout hit while polling for the status of the operation."); } await Task.Delay(pollInterval); } return(operation); }
public static async Task <Operation> PollUntilCompletedAsync(this Operation operation, string projectId, string zone) { ZoneOperationsClient operationsClient = await ZoneOperationsClient.CreateAsync(); GetZoneOperationRequest pollRequest = new GetZoneOperationRequest { Operation = operation.Name, Zone = zone, Project = projectId, }; async Task <Operation> Poller() => await operationsClient.GetAsync(pollRequest); return(await operation.PollUntilCompletedAsync(Poller)); }
/// <summary>Snippet for GetAsync</summary> public async Task GetAsync() { // Snippet: GetAsync(string, string, string, CallSettings) // Additional: GetAsync(string, string, string, CancellationToken) // Create client ZoneOperationsClient zoneOperationsClient = await ZoneOperationsClient.CreateAsync(); // Initialize request argument(s) string project = ""; string zone = ""; string operation = ""; // Make the request Operation response = await zoneOperationsClient.GetAsync(project, zone, operation); // End snippet }
/// <summary>Snippet for GetAsync</summary> public async Task GetRequestObjectAsync() { // Snippet: GetAsync(GetZoneOperationRequest, CallSettings) // Additional: GetAsync(GetZoneOperationRequest, CancellationToken) // Create client ZoneOperationsClient zoneOperationsClient = await ZoneOperationsClient.CreateAsync(); // Initialize request argument(s) GetZoneOperationRequest request = new GetZoneOperationRequest { Zone = "", Operation = "", Project = "", }; // Make the request Operation response = await zoneOperationsClient.GetAsync(request); // End snippet }