Esempio n. 1
0
    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);
    }
Esempio n. 2
0
    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));
    }
Esempio n. 3
0
        /// <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
        }
Esempio n. 4
0
        /// <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
        }