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

chore: move transaction default max retry attempts to a const #1542

Merged
merged 3 commits into from
Jun 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ const CLOUD_RESOURCE_HEADER = 'google-cloud-resource-prefix';
*/
export const MAX_REQUEST_RETRIES = 5;

/*!
* The maximum number of times to attempt committing a transaction before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not just committing it, it is retrying the transaction as a whole. Please rephrase.

* failing.
*/
export const DEFAULT_MAX_TRANSACTION_ATTEMPTS = 5;

/*!
* The default number of idle GRPC channel to keep.
*/
Expand Down Expand Up @@ -994,10 +1000,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 +1011,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