Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add retryOptions passing to underlying Service class #1390

Merged
merged 8 commits into from
Jul 16, 2024
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 @@
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 @@
* 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 @@ -340,17 +362,17 @@
private _universeDomain: string;
private _enableQueryPreview: boolean;

createQueryStream(options?: Query | string): ResourceStream<RowMetadata> {

Check warning on line 365 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<RowMetadata>({}, () => {});
}

getDatasetsStream(options?: GetDatasetsOptions): ResourceStream<Dataset> {

Check warning on line 370 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Dataset>({}, () => {});
}

getJobsStream(options?: GetJobsOptions): ResourceStream<Job> {

Check warning on line 375 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Job>({}, () => {});
}
Expand Down Expand Up @@ -388,6 +410,7 @@
packageJson: require('../../package.json'),
autoRetry: options.autoRetry,
maxRetries: options.maxRetries,
retryOptions: options.retryOptions,
};

if (options.scopes) {
Expand Down Expand Up @@ -1546,7 +1569,7 @@
const parameterMode = is.array(params) ? 'positional' : 'named';
const queryParameters: bigquery.IQueryParameter[] = [];
if (parameterMode === 'named') {
const namedParams = params as {[param: string]: any};

Check warning on line 1572 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
for (const namedParameter of Object.getOwnPropertyNames(namedParams)) {
const value = namedParams[namedParameter];
let queryParameter;
Expand Down Expand Up @@ -2189,7 +2212,7 @@

options = extend({job}, queryOpts, options);
if (res && res.jobComplete) {
let rows: any = [];

Check warning on line 2215 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (res.schema && res.rows) {
rows = BigQuery.mergeSchemaWithRows_(res.schema, res.rows, {
wrapIntegers: options.wrapIntegers || false,
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
Loading