Esempio n. 1
0
        /// <summary>
        /// Asynchronously polls the operation until it is complete, returning the completed operation.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If this object already represents a completed operation, it is returned with no further RPCs.
        /// If <paramref name="metadataCallback"/> is non-null, the callback will be called with any metadata
        /// present before the result is returned.
        /// </para>
        /// <para>
        /// No guarantee is made as to which thread is used for metadata callbacks. However, each callback is
        /// performed synchronously: this method waits for the callback to complete before the operation is next polled.
        /// This guarantees that for a single call, metadata callbacks will never occur in parallel.
        /// </para>
        /// </remarks>
        /// <param name="pollSettings">The settings to use for repeated polling, or null
        /// to use the default poll settings (poll once every 10 seconds, forever).</param>
        /// <param name="callSettings">The call settings to apply on each call, or null for default settings.</param>
        /// <param name="metadataCallback">The callback to invoke with the metadata from each poll operation, even if the metadata is null.</param>
        /// <returns>The completed operation, which can then be checked for errors or a result.</returns>
        public Task <Operation <TResponse, TMetadata> > PollUntilCompletedAsync(
            PollSettings pollSettings           = null,
            CallSettings callSettings           = null,
            Action <TMetadata> metadataCallback = null)
        {
            if (IsCompleted)
            {
                metadataCallback?.Invoke(Metadata);
                return(Task.FromResult(this));
            }

            // We need to work out the effective timing so that we can truncate any deadline, but anything else
            // that's in the effective call settings can be left to the normal merging process. In particular,
            // we don't want to include the header mutation that adds the version header, as otherwise we'll end up
            // including it twice.
            var effectiveTiming = Client.GetEffectiveCallSettingsForGetOperation(callSettings)?.Timing;

            callSettings = callSettings.WithCallTiming(effectiveTiming);
            Func <DateTime?, Task <Operation <TResponse, TMetadata> > > pollAction =
                async deadline =>
            {
                var result = await PollOnceAsync(callSettings.WithEarlierDeadline(deadline, Client.Clock)).ConfigureAwait(false);

                metadataCallback?.Invoke(result.Metadata);
                return(result);
            };

            return(Polling.PollRepeatedlyAsync(
                       pollAction, o => o.IsCompleted,
                       Client.Clock, Client.Scheduler, pollSettings ?? Client.DefaultPollSettings ?? s_defaultPollSettings,
                       callSettings?.CancellationToken ?? CancellationToken.None));
        }
Esempio n. 2
0
        /// <summary>
        /// Asynchronously polls the operation until it is complete, returning the completed operation.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If this object already represents a completed operation, it is returned with no further RPCs.
        /// If <paramref name="metadataCallback"/> is non-null, the callback will be called with any metadata
        /// present before the result is returned.
        /// </para>
        /// <para>
        /// No guarantee is made as to which thread is used for metadata callbacks. However, each callback is
        /// performed synchronously: this method waits for the callback to complete before the operation is next polled.
        /// This guarantees that for a single call, metadata callbacks will never occur in parallel.
        /// </para>
        /// </remarks>
        /// <param name="pollSettings">The settings to use for repeated polling, or null
        /// to use the default poll settings (poll once every 10 seconds, forever).</param>
        /// <param name="callSettings">The call settings to apply on each call, or null for default settings.</param>
        /// <param name="metadataCallback">The callback to invoke with the metadata from each poll operation, even if the metadata is null.</param>
        /// <returns>The completed operation, which can then be checked for errors or a result.</returns>
        public Task <Operation <TResponse, TMetadata> > PollUntilCompletedAsync(
            PollSettings pollSettings           = null,
            CallSettings callSettings           = null,
            Action <TMetadata> metadataCallback = null)
        {
            if (IsCompleted)
            {
                metadataCallback?.Invoke(Metadata);
                return(Task.FromResult(this));
            }
            callSettings = Client.GetEffectiveCallSettingsForGetOperation(callSettings);
            Func <DateTime?, Task <Operation <TResponse, TMetadata> > > pollAction =
                async deadline =>
            {
                var result = await PollOnceAsync(callSettings.WithEarlierDeadline(deadline, Client.Clock)).ConfigureAwait(false);

                metadataCallback?.Invoke(result.Metadata);
                return(result);
            };

            return(Polling.PollRepeatedlyAsync(
                       pollAction, o => o.IsCompleted,
                       Client.Clock, Client.Scheduler, pollSettings ?? Client.DefaultPollSettings ?? s_defaultPollSettings,
                       callSettings?.CancellationToken ?? CancellationToken.None));
        }
        /// <summary>
        /// Asynchronously but eagerly fetches a set of rows, up to the specified count, providing a page of results with a next page token
        /// if more results are available. This is typically used within web applications, where the next page token
        /// is propagated to the client along with the results, so that the next page can be retrieved in another request.
        /// If the job is still incompleted, it is polled until it has completed.
        /// </summary>
        /// <remarks>
        /// If <paramref name="pageSize"/> is smaller than the number of rows originally requested,
        /// this may require another server call to retrieve an appropriate page token. When working
        /// in pages, always specify a maximum per-request number of rows less than or equal to the
        /// page size you want.
        /// </remarks>
        /// <param name="pageSize">The maximum number of rows to retrieve. Must be positive.</param>
        /// <param name="pollSettings">The settings to control how often and long the job is fetched before timing out if it is still incomplete.
        /// May be null, in which case defaults will be supplied.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A task representing the asynchronous operation. When complete, the result is
        /// an in-memory result set of at most the given number of rows.</returns>
        public async Task <BigQueryPage> ReadPageAsync(int pageSize, PollSettings pollSettings = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            GaxPreconditions.CheckArgumentRange(pageSize, nameof(pageSize), 1, int.MaxValue);
            var job = await PollUntilCompletedAsync(pollSettings, cancellationToken).ConfigureAwait(false);

            return(await job.ReadPageAsyncImpl(pageSize, cancellationToken).ConfigureAwait(false));
        }
Esempio n. 4
0
        public async Task PollUntilCompletedAsync_AlreadyCompleted()
        {
            var client = new FakeOperationsClient();

            client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc(), new StringValue {
                Value = "result"
            });
            var initial = Operation <StringValue, Timestamp> .PollOnceFromName("op", client);

            Assert.True(initial.IsCompleted);
            var expectedMetadata            = GenerateExpectedMetadata(client.Clock, 0);
            List <Timestamp> actualMetadata = new List <Timestamp>();
            await client.FakeScheduler.RunAsync(async() =>
            {
                Assert.Equal(1, client.RequestCount);
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                var final    = await initial.PollUntilCompletedAsync(settings, metadataCallback: actualMetadata.Add);
                Assert.Equal("result", final.Result.Value);
                // No more requests due to PollUntilCompletedAsync call
                Assert.Equal(1, client.RequestCount);
            });

            // Metadata was still added despite no RPCs being made
            Assert.Equal(expectedMetadata, actualMetadata);
        }
Esempio n. 5
0
        /// <summary>
        /// Polls the operation until it is complete, returning the completed operation.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If this object already represents a completed operation, it is returned with no further RPCs.
        /// If <paramref name="metadataCallback"/> is non-null, the callback will be called with any metadata
        /// present before the result is returned.
        /// </para>
        /// <para>
        /// Each callback is performed synchronously: this method waits for the callback to complete before the operation is next polled.
        /// This guarantees that for a single call, metadata callbacks will never occur in parallel.
        /// </para>
        /// </remarks>
        /// <param name="pollSettings">The settings to use for repeated polling, or null
        /// to use the default poll settings (poll once every 10 seconds, forever).</param>
        /// <param name="callSettings">The call settings to apply on each call, or null for default settings.</param>
        /// <param name="metadataCallback">The callback to invoke with the metadata from each poll operation, even if the metadata is null.</param>
        /// <returns>The completed operation, which can then be checked for errors or a result.</returns>
        public Operation <TResponse, TMetadata> PollUntilCompleted(
            PollSettings pollSettings           = null,
            CallSettings callSettings           = null,
            Action <TMetadata> metadataCallback = null)
        {
            if (IsCompleted)
            {
                metadataCallback?.Invoke(Metadata);
                return(this);
            }
            callSettings = Client.GetEffectiveCallSettingsForGetOperation(callSettings);

            Func <DateTime?, Operation <TResponse, TMetadata> > pollAction =
                deadline =>
            {
                var result = PollOnce(callSettings.WithEarlierDeadline(deadline, Client.Clock));
                metadataCallback?.Invoke(result.Metadata);
                return(result);
            };

            return(Polling.PollRepeatedly(
                       pollAction, o => o.IsCompleted,
                       Client.Clock, Client.Scheduler, pollSettings ?? Client.DefaultPollSettings ?? s_defaultPollSettings,
                       callSettings?.CancellationToken ?? CancellationToken.None));
        }
Esempio n. 6
0
 public void SuccessfulConstruction()
 {
     var expiration = Expiration.FromTimeout(TimeSpan.FromSeconds(1));
     var delay = TimeSpan.FromSeconds(2);
     var settings = new PollSettings(expiration, delay);
     Assert.Same(expiration, settings.Expiration);
     Assert.Equal(delay, settings.Delay);
 }
        /// <summary>
        /// Polls the server until the batch job execution finishes by setting the total
        /// time to wait before time-out.
        /// </summary>
        /// <param name="operationResponse">The operation response used to poll the server.</param>
        private static void PollBatchJob(Operation <Empty, BatchJobMetadata> operationResponse)
        {
            PollSettings pollSettings = new PollSettings(
                Expiration.FromTimeout(TimeSpan.FromSeconds(MAX_TOTAL_POLL_INTERVAL_SECONDS)),
                TimeSpan.FromSeconds(1));

            operationResponse.PollUntilCompleted(pollSettings);
        }
 /// <inheritdoc />
 public override Task <BigQueryJob> PollJobUntilCompletedAsync(JobReference jobReference, GetJobOptions options = null,
                                                               PollSettings pollSettings = null, CancellationToken cancellationToken = default)
 {
     GaxPreconditions.CheckNotNull(jobReference, nameof(jobReference));
     return(Polling.PollRepeatedlyAsync(ignoredDeadline => GetJobAsync(jobReference, options, cancellationToken),
                                        job => job.State == JobState.Done,
                                        Clock, Scheduler, pollSettings ?? s_defaultPollSettings, cancellationToken));
 }
 public AsyncRowEnumerator(BigQueryResults job, PollSettings pollSettings)
 {
     _job                = job;
     _pollSettings       = pollSettings;
     _options            = _job._options?.Clone() ?? new GetQueryResultsOptions();
     _options.StartIndex = null;
     _options.PageToken  = _job._response.PageToken;
 }
Esempio n. 10
0
        public void SuccessfulConstruction()
        {
            var expiration = Expiration.FromTimeout(TimeSpan.FromSeconds(1));
            var delay      = TimeSpan.FromSeconds(2);
            var settings   = new PollSettings(expiration, delay);

            Assert.Same(expiration, settings.Expiration);
            Assert.Equal(delay, settings.Delay);
        }
Esempio n. 11
0
 public void PollToCompletion_Success()
 {
     var pollSource = new PollSource(TimeSpan.FromSeconds(3), 5);
     var pollSettings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
     pollSource.Scheduler.Run(() =>
     {
         var result = pollSource.PollRepeatedly(pollSettings);
         Assert.Equal(5, result);
         Assert.Equal(TimeSpan.FromSeconds(4), pollSource.RunningTime);
     });
 }
Esempio n. 12
0
 public async Task PollToCompletionAsync_Success()
 {
     var pollSource = new PollSource(TimeSpan.FromSeconds(3), 5);
     var pollSettings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
     await pollSource.Scheduler.RunAsync(async () =>
     {
         var result = await pollSource.PollRepeatedlyAsync(pollSettings);
         Assert.Equal(5, result);
         Assert.Equal(TimeSpan.FromSeconds(4), pollSource.RunningTime);
     });
 }
Esempio n. 13
0
        /// <summary>
        /// Asynchronously polls the operation until it is complete, returning the completed operation.
        /// </summary>
        /// <remarks>
        /// If this object already represents a completed operation, it is returned immediately,
        /// with no further RPCs.
        /// </remarks>
        /// <param name="pollSettings">The settings to use for repeated polling, or null
        /// to use the default poll settings (poll once every 10 seconds, forever).</param>
        /// <param name="callSettings">The call settings to apply on each call, or null for default settings.</param>
        /// <returns>The completed operation, which can then be checked for errors or a result.</returns>
        public Task <Operation <T> > PollUntilCompletedAsync(PollSettings pollSettings = null, CallSettings callSettings = null)
        {
            if (IsCompleted)
            {
                return(Task.FromResult(this));
            }
            // TODO: Use the deadline.
            Func <DateTime?, Task <Operation <T> > > pollAction = deadline => PollOnceAsync(callSettings);

            return(Polling.PollRepeatedlyAsync(pollAction, o => o.IsCompleted, Client.Clock, Client.Scheduler, pollSettings ?? s_defaultPollSettings));
        }
Esempio n. 14
0
 public async Task PollToCompletionAsync_Timeout()
 {
     var pollSource = new PollSource(TimeSpan.FromSeconds(10), 5);
     var pollSettings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
     await pollSource.Scheduler.RunAsync(async () =>
     {
         await Assert.ThrowsAsync<TimeoutException>(() => pollSource.PollRepeatedlyAsync(pollSettings));
         // We give up at t=4 because the next call would be after the expiration.
         Assert.Equal(TimeSpan.FromSeconds(4), pollSource.RunningTime);
     });
 }
Esempio n. 15
0
 public async Task PollToCompletionAsync_Timeout()
 {
     var pollSource   = new PollSource(TimeSpan.FromSeconds(10), 5);
     var pollSettings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
     await pollSource.Scheduler.RunAsync(async() =>
     {
         await Assert.ThrowsAsync <TimeoutException>(() => pollSource.PollRepeatedlyAsync(pollSettings, CancellationToken.None));
         // We give up at t=4 because the next call would be after the expiration.
         Assert.Equal(TimeSpan.FromSeconds(4), pollSource.RunningTime);
     });
 }
Esempio n. 16
0
 public async Task PollToCompletionExponentialAsync_Success()
 {
     var pollSource   = new PollSource(TimeSpan.FromSeconds(7), 5);
     var pollSettings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(20)), TimeSpan.FromSeconds(1), 2.0, TimeSpan.FromSeconds(3));
     await pollSource.Scheduler.RunAsync(async() =>
     {
         var result = await pollSource.PollRepeatedlyAsync(pollSettings, CancellationToken.None);
         Assert.Equal(5, result);
         Assert.Equal(TimeSpan.FromSeconds(9), pollSource.RunningTime);
     });
 }
Esempio n. 17
0
        public void SuccessfulConstructionExponential()
        {
            var expiration = Expiration.FromTimeout(TimeSpan.FromSeconds(1));
            var delay      = TimeSpan.FromSeconds(2);
            var maxDelay   = TimeSpan.FromSeconds(3);
            var settings   = new PollSettings(expiration, delay, 2.0, maxDelay);

            Assert.Same(expiration, settings.Expiration);
            Assert.Equal(delay, settings.Delay);
            Assert.Equal(2.0, settings.DelayMultiplier);
            Assert.Equal(maxDelay, settings.MaxDelay);
        }
Esempio n. 18
0
        public void PollToCompletion_Success()
        {
            var pollSource   = new PollSource(TimeSpan.FromSeconds(3), 5);
            var pollSettings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));

            pollSource.Scheduler.Run(() =>
            {
                var result = pollSource.PollRepeatedly(pollSettings, CancellationToken.None);
                Assert.Equal(5, result);
                Assert.Equal(TimeSpan.FromSeconds(4), pollSource.RunningTime);
            });
        }
Esempio n. 19
0
        public void PollJobUntilCompletedEquivalents()
        {
            var jobId        = "job";
            var reference    = GetJobReference(jobId);
            var options      = new GetJobOptions();
            var pollSettings = new PollSettings(Expiration.None, TimeSpan.Zero);

            VerifyEquivalent(new BigQueryJob(new DerivedBigQueryClient(), GetJob(reference)),
                             client => client.PollJobUntilCompleted(MatchesWhenSerialized(reference), options, pollSettings),
                             client => client.PollJobUntilCompleted(jobId, options, pollSettings),
                             client => client.PollJobUntilCompleted(ProjectId, jobId, options, pollSettings),
                             client => new BigQueryJob(client, GetJob(reference)).PollUntilCompleted(options, pollSettings));
        }
        /// <summary>
        /// Asynchronously polls the operation until it is complete, returning the completed operation.
        /// </summary>
        /// <remarks>
        /// If this object already represents a completed operation, it is returned immediately,
        /// with no further RPCs.
        /// </remarks>
        /// <param name="pollSettings">The settings to use for repeated polling, or null
        /// to use the default poll settings (poll once every 10 seconds, forever).</param>
        /// <param name="callSettings">The call settings to apply on each call, or null for default settings.</param>
        /// <returns>The completed operation, which can then be checked for errors or a result.</returns>
        public Task <Operation <T> > PollUntilCompletedAsync(PollSettings pollSettings = null, CallSettings callSettings = null)
        {
            if (IsCompleted)
            {
                return(Task.FromResult(this));
            }
            callSettings = Client.GetEffectiveCallSettingsForGetOperation(callSettings);
            Func <DateTime?, Task <Operation <T> > > pollAction = deadline => PollOnceAsync(callSettings.WithEarlierDeadline(deadline, Client.Clock));

            return(Polling.PollRepeatedlyAsync(
                       pollAction, o => o.IsCompleted,
                       Client.Clock, Client.Scheduler, pollSettings ?? s_defaultPollSettings,
                       callSettings?.CancellationToken ?? CancellationToken.None));
        }
Esempio n. 21
0
        public void PollJobUntilCompletedAsyncEquivalents()
        {
            var jobId        = "job";
            var reference    = GetJobReference(jobId);
            var options      = new GetJobOptions();
            var pollSettings = new PollSettings(Expiration.None, TimeSpan.Zero);
            var token        = new CancellationTokenSource().Token;

            VerifyEquivalentAsync(new BigqueryJob(new DerivedBigqueryClient(), GetJob(reference)),
                                  client => client.PollJobUntilCompletedAsync(MatchesWhenSerialized(reference), options, pollSettings, token),
                                  client => client.PollJobUntilCompletedAsync(jobId, options, pollSettings, token),
                                  client => client.PollJobUntilCompletedAsync(ProjectId, jobId, options, pollSettings, token),
                                  client => new BigqueryJob(client, GetJob(reference)).PollUntilCompletedAsync(options, pollSettings, token));
        }
Esempio n. 22
0
        /// <summary>
        /// Polls the operation until it is complete, returning the completed operation.
        /// </summary>
        /// <remarks>
        /// If this object already represents a completed operation, it is returned immediately,
        /// with no further RPCs.
        /// </remarks>
        /// <param name="pollSettings">The settings to use for repeated polling, or null
        /// to use the default poll settings (poll once every 10 seconds, forever).</param>
        /// <param name="callSettings">The call settings to apply on each call, or null for default settings.</param>
        /// <returns>The completed operation, which can then be checked for errors or a result.</returns>
        public Operation <T> PollUntilCompleted(PollSettings pollSettings = null, CallSettings callSettings = null)
        {
            if (IsCompleted)
            {
                return(this);
            }
            // TODO: Use the deadline and get a cancellation token from the effective call settings.
            Func <DateTime?, Operation <T> > pollAction = deadline => PollOnce(callSettings);

            return(Polling.PollRepeatedly(
                       pollAction, o => o.IsCompleted,
                       Client.Clock, Client.Scheduler, pollSettings ?? s_defaultPollSettings,
                       CancellationToken.None));
        }
Esempio n. 23
0
        public async Task PollUntilCompletedAsync_Timeout()
        {
            var client = new FakeOperationsClient();
            await client.FakeScheduler.RunAsync(async() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(10), new StringValue {
                    Value = "result"
                });
                var initial = Operation <StringValue> .PollOnceFromNameAsync("op", client).Result;
                // Second request at t=0, then at t=2, then at t=4, then we give up.
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                await Assert.ThrowsAsync <TimeoutException>(() => initial.PollUntilCompletedAsync(settings));
            });

            Assert.Equal(4, client.RequestCount);
        }
Esempio n. 24
0
        public async Task PollUntilCompletedAsync_Success()
        {
            var client = new FakeOperationsClient();
            await client.FakeScheduler.RunAsync(async() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                    Value = "result"
                });
                var initial  = Operation <StringValue> .PollOnceFromNameAsync("op", client).Result;
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                // Second request at t=2, then another at t=4
                var completedOperation = await initial.PollUntilCompletedAsync(settings);
                Assert.Equal("result", completedOperation.Result.Value);
            });

            Assert.Equal(4, client.RequestCount);
        }
Esempio n. 25
0
        public void PollUntilCompleted_Success()
        {
            var client = new FakeOperationsClient();

            client.FakeScheduler.Run(() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                    Value = "result"
                });
                var initial  = Operation <StringValue> .PollOnceFromName("op", client);
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                // Second request at t=2, then another at t=4
                var final = initial.PollUntilCompleted(settings);
                Assert.Equal("result", final.Result.Value);
                Assert.Equal(4, client.RequestCount);
                return(0); // TODO: Remove the need for this, by improving FakeScheduler.
            });
        }
Esempio n. 26
0
        public void PollUntilCompleted_Timeout()
        {
            var client                      = new FakeOperationsClient();
            var expectedMetadata            = GenerateExpectedMetadata(client.Clock, 0, 2, 4);
            List <Timestamp> actualMetadata = new List <Timestamp>();

            client.FakeScheduler.Run(() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(10), new StringValue {
                    Value = "result"
                });
                var initial = Operation <StringValue, Timestamp> .PollOnceFromName("op", client);
                // Second request at t=0, then at t=2, then at t=4, then we give up.
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                Assert.Throws <TimeoutException>(() => initial.PollUntilCompleted(settings, metadataCallback: actualMetadata.Add));
                Assert.Equal(4, client.RequestCount);
            });
            Assert.Equal(expectedMetadata, actualMetadata);
        }
Esempio n. 27
0
        public void PollQueryUntilCompletedEquivalents()
        {
            var jobId     = "job";
            var reference = GetJobReference(jobId);
            var getQueryResultsOptions = new GetQueryResultsOptions();
            var pollSettings           = new PollSettings(Expiration.None, TimeSpan.Zero);

            VerifyEquivalent(
                new BigQueryResults(new DerivedBigQueryClient(), new GetQueryResultsResponse {
                JobReference = reference
            }, getQueryResultsOptions),
                client => client.PollQueryUntilCompleted(MatchesWhenSerialized(reference), getQueryResultsOptions, pollSettings),
                client => client.PollQueryUntilCompleted(jobId, getQueryResultsOptions, pollSettings),
                client => client.PollQueryUntilCompleted(ProjectId, jobId, getQueryResultsOptions, pollSettings),
                client => new BigQueryJob(client, GetJob(reference)).PollQueryUntilCompleted(getQueryResultsOptions, pollSettings),
                client => new BigQueryResults(client, new GetQueryResultsResponse {
                JobReference = reference
            }, getQueryResultsOptions).PollUntilCompleted(pollSettings));
        }
Esempio n. 28
0
        public async Task PollUntilCompletedAsync_Success()
        {
            var client                      = new FakeOperationsClient();
            var expectedMetadata            = GenerateExpectedMetadata(client.Clock, 0, 2, 3);
            List <Timestamp> actualMetadata = new List <Timestamp>();
            await client.FakeScheduler.RunAsync(async() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                    Value = "result"
                });
                var initial  = Operation <StringValue, Timestamp> .PollOnceFromNameAsync("op", client).Result;
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                // Second request at t=0, then at t=2, then another at t=4
                var completedOperation = await initial.PollUntilCompletedAsync(settings, metadataCallback: actualMetadata.Add);
                Assert.Equal("result", completedOperation.Result.Value);
            });

            Assert.Equal(4, client.RequestCount);
            Assert.Equal(expectedMetadata, actualMetadata);
        }
Esempio n. 29
0
        /// <summary>
        /// Polls the operation until it is complete, returning the completed operation.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If this object already represents a completed operation, it is returned with no further RPCs.
        /// If <paramref name="metadataCallback"/> is non-null, the callback will be called with any metadata
        /// present before the result is returned.
        /// </para>
        /// <para>
        /// Each callback is performed synchronously: this method waits for the callback to complete before the operation is next polled.
        /// This guarantees that for a single call, metadata callbacks will never occur in parallel.
        /// </para>
        /// </remarks>
        /// <param name="pollSettings">The settings to use for repeated polling, or null
        /// to use the default poll settings (poll once every 10 seconds, forever).</param>
        /// <param name="callSettings">The call settings to apply on each call, or null for default settings.</param>
        /// <param name="metadataCallback">The callback to invoke with the metadata from each poll operation, even if the metadata is null.</param>
        /// <returns>The completed operation, which can then be checked for errors or a result.</returns>
        public Operation <TResponse, TMetadata> PollUntilCompleted(
            PollSettings pollSettings           = null,
            CallSettings callSettings           = null,
            Action <TMetadata> metadataCallback = null)
        {
            if (IsCompleted)
            {
                metadataCallback?.Invoke(Metadata);
                return(this);
            }

            // We need to work out the effective expiration so that we can truncate any deadline, but anything else
            // that's in the effective call settings can be left to the normal merging process. In particular,
            // we don't want to include the header mutation that adds the version header, as otherwise we'll end up
            // including it twice.
            var effectiveExpiration = Client.GetEffectiveCallSettingsForGetOperation(callSettings)?.Expiration;

            if (effectiveExpiration != null)
            {
                callSettings = callSettings.WithExpiration(effectiveExpiration);
            }
            // TODO: Retry settings?

            Func <DateTime?, Operation <TResponse, TMetadata> > pollAction =
                deadline =>
            {
                var result = PollOnce(callSettings.WithEarlierDeadline(deadline, Client.Clock));
                metadataCallback?.Invoke(result.Metadata);
                return(result);
            };

            return(Polling.PollRepeatedly(
                       pollAction, o => o.IsCompleted,
                       Client.Clock, Client.Scheduler, pollSettings ?? Client.DefaultPollSettings ?? s_defaultPollSettings,
                       callSettings?.CancellationToken ?? CancellationToken.None));
        }
Esempio n. 30
0
        public void PollUntilCompleted_NullMetadata()
        {
            var client = new FakeOperationsClient {
                GenerateMetadata = false
            };
            var expectedMetadata = new List <Timestamp> {
                null, null, null
            };
            List <Timestamp> actualMetadata = new List <Timestamp>();

            client.FakeScheduler.Run(() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                    Value = "result"
                });
                var initial  = Operation <StringValue, Timestamp> .PollOnceFromName("op", client);
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                // Second request at t=2, then another at t=4
                var final = initial.PollUntilCompleted(settings, metadataCallback: actualMetadata.Add);
                Assert.Equal("result", final.Result.Value);
                Assert.Equal(4, client.RequestCount);
            });
            Assert.Equal(expectedMetadata, actualMetadata);
        }
 /// <summary>
 /// Polls the specified job within this client's project for completion.
 /// This method just creates a <see cref="JobReference"/> and delegates to <see cref="PollJobUntilCompleted(JobReference, GetJobOptions, PollSettings)"/>.
 /// </summary>
 /// <param name="jobId">The job ID. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="pollSettings">The settings to control how often and long the job is fetched before timing out if it is still incomplete. May be null, in which case defaults will be supplied.</param>
 /// <returns>The completed job.</returns>
 public virtual BigQueryJob PollJobUntilCompleted(string jobId, GetJobOptions options = null, PollSettings pollSettings = null) =>
 PollJobUntilCompleted(GetJobReference(jobId), options, pollSettings);
 /// <summary>
 /// Asynchronously polls the specified job for completion.
 /// </summary>
 /// <param name="jobReference">A fully-qualified identifier for the job. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="pollSettings">The settings to control how often and long the job is fetched before timing out if it is still incomplete. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the completed job.</returns>
 public virtual Task <BigQueryJob> PollJobUntilCompletedAsync(JobReference jobReference, GetJobOptions options = null, PollSettings pollSettings = null, CancellationToken cancellationToken = default(CancellationToken)) =>
 throw new NotImplementedException();
 /// <summary>
 /// Asynchronously polls the specified job for completion.
 /// This method just creates a <see cref="JobReference"/> and delegates to <see cref="PollJobUntilCompletedAsync(JobReference, GetJobOptions, PollSettings, CancellationToken)"/>.
 /// </summary>
 /// <param name="projectId">The project ID. Must not be null.</param>
 /// <param name="jobId">The job ID. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="pollSettings">The settings to control how often and long the job is fetched before timing out if it is still incomplete. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the completed job.</returns>
 public virtual Task <BigQueryJob> PollJobUntilCompletedAsync(string projectId, string jobId, GetJobOptions options = null, PollSettings pollSettings = null, CancellationToken cancellationToken = default(CancellationToken)) =>
 PollJobUntilCompletedAsync(GetJobReference(projectId, jobId), options, pollSettings, cancellationToken);
Esempio n. 34
0
 internal int PollRepeatedly(PollSettings pollSettings)
     => Polling.PollRepeatedly(Poll, IsPositive, Clock, Scheduler, pollSettings);
Esempio n. 35
0
 internal Task<int> PollRepeatedlyAsync(PollSettings pollSettings)
     => Polling.PollRepeatedlyAsync(PollAsync, IsPositive, Clock, Scheduler, pollSettings);
 /// <summary>
 /// Polls the specified job for completion.
 /// </summary>
 /// <param name="jobReference">A fully-qualified identifier for the job. Must not be null.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="pollSettings">The settings to control how often and long the job is fetched before timing out if it is still incomplete. May be null, in which case defaults will be supplied.</param>
 /// <returns>The completed job.</returns>
 public virtual BigQueryJob PollJobUntilCompleted(JobReference jobReference, GetJobOptions options = null, PollSettings pollSettings = null) =>
 throw new NotImplementedException();