Skip to content

Commit

Permalink
feat: add retryOptions passing to underlying Service class (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarowolfx authored Jul 16, 2024
1 parent 264bc75 commit a7cd3af
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import {
JobResponse,
RowMetadata,
} from './table';
import {GoogleErrorBody} from '@google-cloud/common/build/src/util';
import {
GoogleErrorBody,
RetryOptions,
} from '@google-cloud/common/build/src/util';
import bigquery from './types';
import {logger, setLogFunction} from './logger';

Expand Down Expand Up @@ -216,16 +219,35 @@ export interface BigQueryOptions extends GoogleAuthOptions {
* We will exponentially backoff subsequent requests by default.
*
* Defaults to `true`.
*
* @deprecated Use retryOptions.
*/
autoRetry?: boolean;
/**
* Maximum number of automatic retries
* attempted before returning the error.
*
* Defaults to 3.
*
* @deprecated Use retryOptions.
*/
maxRetries?: number;

/**
* Customize retry configuration for all requests in the SDK.
* By default, a request is retried if the response is related to rate limits
* or certain intermittent server errors.
* We will exponentially backoff subsequent requests by default.
*
* More on the default retry predicate on the `shouldRetryRequest` method:
* https://github.com/googleapis/nodejs-common/blob/main/src/util.ts
*
* Defaults:
* - retryOptions.autoRetry: true
* - retryOptions.maxRetries: 3
*/
retryOptions?: RetryOptions;

/**
* The geographic location of all datasets and
* jobs referenced and created through the client.
Expand Down Expand Up @@ -388,6 +410,7 @@ export class BigQuery extends Service {
packageJson: require('../../package.json'),
autoRetry: options.autoRetry,
maxRetries: options.maxRetries,
retryOptions: options.retryOptions,
};

if (options.scopes) {
Expand Down
13 changes: 13 additions & 0 deletions test/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ describe('BigQuery', () => {
assert.deepStrictEqual(calledWith.maxRetries, retryVal);
});

it('should pass retryOptions from options', () => {
const retryOptions = {
autoRetry: true,
maxRetries: 3,
};
const bq = new BigQuery({
retryOptions: retryOptions,
});

const calledWith = bq.calledWith_[0];
assert.deepStrictEqual(calledWith.retryOptions, retryOptions);
});

it('should not modify options argument', () => {
const options = {
projectId: PROJECT_ID,
Expand Down

0 comments on commit a7cd3af

Please sign in to comment.