Skip to content

Commit

Permalink
chore: move transaction default max retry attempts to a const (#1542)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Chen committed Jun 24, 2021
1 parent 113200a commit 7473343
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ const CLOUD_RESOURCE_HEADER = 'google-cloud-resource-prefix';
*/
export const MAX_REQUEST_RETRIES = 5;

/*!
* The maximum number of times to attempt a transaction before failing.
*/
export const DEFAULT_MAX_TRANSACTION_ATTEMPTS = 5;

/*!
* The default number of idle GRPC channel to keep.
*/
Expand Down Expand Up @@ -994,10 +999,9 @@ export class Firestore implements firestore.Firestore {
): Promise<T> {
validateFunction('updateFunction', updateFunction);

const defaultAttempts = 5;
const tag = requestTag();

let maxAttempts: number;
let maxAttempts = DEFAULT_MAX_TRANSACTION_ATTEMPTS;

if (transactionOptions) {
validateObject('transactionOptions', transactionOptions);
Expand All @@ -1006,9 +1010,8 @@ export class Firestore implements firestore.Firestore {
transactionOptions.maxAttempts,
{optional: true, minValue: 1}
);
maxAttempts = transactionOptions.maxAttempts || defaultAttempts;
} else {
maxAttempts = defaultAttempts;
maxAttempts =
transactionOptions.maxAttempts || DEFAULT_MAX_TRANSACTION_ATTEMPTS;
}

const transaction = new Transaction(this, tag);
Expand Down

0 comments on commit 7473343

Please sign in to comment.