/// <inheritdoc />
 public override BigQueryJob PollJobUntilCompleted(JobReference jobReference, GetJobOptions options = null, PollSettings pollSettings = null)
 {
     GaxPreconditions.CheckNotNull(jobReference, nameof(jobReference));
     return(Polling.PollRepeatedly(ignoredDeadline => GetJob(jobReference, options),
                                   job => job.State == JobState.Done,
                                   Clock, Scheduler, pollSettings ?? s_defaultPollSettings, CancellationToken.None));
 }
Exemplo n.º 2
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 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?, 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));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Polls until this table contains at least the given number of rows. This should be used carefully, only where we know the table won't be huge.
 /// </summary>
 /// <remarks>
 /// <para>
 /// This method is designed to make integration tests more reliable: after an insert, data fetching (with queries or ListRows)
 /// may not see the new data.
 /// </para>
 /// <para>
 /// We've tried using the data in BigQueryTable.Resource.NumRows and BigQueryTable.Resource.StreamingBuffer, but they're not as reliable as
 /// just reading the rows.
 /// </para>
 /// </remarks>
 /// <param name="expectedRows">The number of rows expected.</param>
 /// <param name="pollSettings">The poll settings to use, or null to use the defaults (poll once every 2 seconds, 30 second timeout)</param>
 /// <returns>The actual number of rows in the table.</returns>
 /// <exception cref="TimeoutException">The timeout specified in the poll settings elapsed before the streaming buffer became empty.</exception>
 public static int PollUntilRowCountIsAtLeast(this BigQueryTable table, int expectedRows, PollSettings pollSettings = null) =>
 Polling.PollRepeatedly(
     ignoredDeadline => table.ListRows().Count(),
     count => count >= expectedRows,
     SystemClock.Instance,
     SystemScheduler.Instance,
     pollSettings ?? s_defaultStreamingBufferPollSettings,
     CancellationToken.None);
Exemplo n.º 5
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.
            Func <DateTime?, Operation <T> > pollAction = deadline => PollOnce(callSettings);

            return(Polling.PollRepeatedly(pollAction, o => o.IsCompleted, Client.Clock, Client.Scheduler, pollSettings ?? s_defaultPollSettings));
        }
Exemplo n.º 6
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));
        }
        /// <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);
            }
            callSettings = Client.GetEffectiveCallSettingsForGetOperation(callSettings);

            Func <DateTime?, Operation <T> > pollAction = deadline => PollOnce(callSettings.WithEarlierDeadline(deadline, Client.Clock));

            return(Polling.PollRepeatedly(
                       pollAction, o => o.IsCompleted,
                       Client.Clock, Client.Scheduler, pollSettings ?? s_defaultPollSettings,
                       callSettings?.CancellationToken ?? CancellationToken.None));
        }
Exemplo n.º 8
0
 internal int PollRepeatedly(PollSettings pollSettings, CancellationToken cancellationToken)
 => Polling.PollRepeatedly(Poll, IsPositive, Clock, Scheduler, pollSettings, cancellationToken);
 /// <inheritdoc />
 public override BigqueryQueryJob PollQueryUntilCompleted(JobReference jobReference, GetQueryResultsOptions options = null, PollSettings pollSettings = null)
 {
     GaxPreconditions.CheckNotNull(jobReference, nameof(jobReference));
     return(Polling.PollRepeatedly(ignoredDeadline => GetQueryResults(jobReference, options),
                                   job => job.Completed, Clock, Scheduler, pollSettings ?? s_defaultPollSettings));
 }