Exemple #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));
        }
Exemple #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));
        }
 /// <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));
 }
        /// <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));
        }
        /// <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));
        }
Exemple #6
0
        public async Task CheckConsistencyAsync()
        {
            // TODO: When replication goes to beta or GA, having something cleaner available than what is below.

            // Snippet: CheckConsistencyAsync(TableName,string,CallSettings)
            // Additional: GenerateConsistencyTokenAsync(TableName,CallSettings)
            BigtableTableAdminClient adminClient = await BigtableTableAdminClient.CreateAsync();

            BigtableTableAdminSettings settings   = BigtableTableAdminSettings.GetDefault();
            CallSettings generateSettings         = settings.GenerateConsistencyTokenSettings;
            CallSettings checkConsistencySettings = settings.CheckConsistencySettings;

            // Create a consistency token for the table.
            TableName tableName = new TableName("[PROJECT]", "[INSTANCE]", "[TABLE]");
            GenerateConsistencyTokenResponse generateResponse =
                await adminClient.GenerateConsistencyTokenAsync(tableName, generateSettings);

            string consistencyToken = generateResponse.ConsistencyToken;

            // Check for consistency for 60 seconds at 10 second intervals.
            TimeSpan pollingTimeout  = TimeSpan.FromSeconds(60);
            TimeSpan pollingInterval = TimeSpan.FromSeconds(10);
            CheckConsistencyResponse checkConsistencyResponse =
                await Polling.PollRepeatedlyAsync(
                    deadline => adminClient.CheckConsistencyAsync(
                        tableName,
                        consistencyToken,
                        checkConsistencySettings.WithEarlierDeadline(deadline, settings.Clock)),
                    response => response.Consistent,
                    settings.Clock,
                    settings.Scheduler,
                    new PollSettings(Expiration.FromTimeout(pollingTimeout), pollingInterval),
                    checkConsistencySettings.CancellationToken ?? CancellationToken.None);

            if (checkConsistencyResponse.Consistent)
            {
                // Replication has caught up.
            }
            // End snippet
        }
Exemple #7
0
 internal Task <int> PollRepeatedlyAsync(PollSettings pollSettings, CancellationToken cancellationToken)
 => Polling.PollRepeatedlyAsync(PollAsync, IsPositive, Clock, Scheduler, pollSettings, cancellationToken);
 /// <inheritdoc />
 public override Task <BigqueryQueryJob> PollQueryUntilCompletedAsync(JobReference jobReference, GetQueryResultsOptions options = null, PollSettings pollSettings = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     GaxPreconditions.CheckNotNull(jobReference, nameof(jobReference));
     return(Polling.PollRepeatedlyAsync(ignoredDeadline => GetQueryResultsAsync(jobReference, options, cancellationToken),
                                        job => job.Completed, Clock, Scheduler, pollSettings ?? s_defaultPollSettings));
 }