GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: Unify precondition retry logic (#1660) · googleapis/google-cloud-node@f03aee1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handwritten/storage/src
    • file.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handwritten/storage/src/file.ts‎

Copy file name to clipboardExpand all lines: handwritten/storage/src/file.ts
+28-14Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,28 @@ class File extends ServiceObject<File> {
854854
this.instancePreconditionOpts = options?.preconditionOpts;
855855
}
856856

857+
/**
858+
* A helper method for determining if a request should be retried based on preconditions.
859+
* This should only be used for methods where the idempotency is determined by
860+
* `ifGenerationMatch`
861+
*
862+
* A request should not be retried under the following conditions:
863+
* - if precondition option `ifGenerationMatch` is not set OR
864+
* - if `idempotencyStrategy` is set to `RetryNever`
865+
*/
866+
private shouldRetryBasedOnPreconditionAndIdempotencyStrat(
867+
options?: PreconditionOptions
868+
): boolean {
869+
return !(
870+
(options?.ifGenerationMatch === undefined &&
871+
this.instancePreconditionOpts?.ifGenerationMatch === undefined &&
872+
this.storage.retryOptions.idempotencyStrategy ===
873+
IdempotencyStrategy.RetryConditional) ||
874+
this.storage.retryOptions.idempotencyStrategy ===
875+
IdempotencyStrategy.RetryNever
876+
);
877+
}
878+
857879
copy(
858880
destination: string | Bucket | File,
859881
options?: CopyOptions
@@ -3667,15 +3689,11 @@ class File extends ServiceObject<File> {
36673689
const options =
36683690
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
36693691

3670-
// Do not retry if precondition option ifGenerationMatch is not set
36713692
let maxRetries = this.storage.retryOptions.maxRetries;
36723693
if (
3673-
(options?.preconditionOpts?.ifGenerationMatch === undefined &&
3674-
this.instancePreconditionOpts?.ifGenerationMatch === undefined &&
3675-
this.storage.retryOptions.idempotencyStrategy ===
3676-
IdempotencyStrategy.RetryConditional) ||
3677-
this.storage.retryOptions.idempotencyStrategy ===
3678-
IdempotencyStrategy.RetryNever
3694+
!this.shouldRetryBasedOnPreconditionAndIdempotencyStrat(
3695+
options?.preconditionOpts
3696+
)
36793697
) {
36803698
maxRetries = 0;
36813699
}
@@ -3852,15 +3870,11 @@ class File extends ServiceObject<File> {
38523870
options
38533871
);
38543872

3855-
// Do not retry if precondition option ifGenerationMatch is not set
38563873
const retryOptions = this.storage.retryOptions;
38573874
if (
3858-
(options?.preconditionOpts?.ifGenerationMatch === undefined &&
3859-
this.instancePreconditionOpts?.ifGenerationMatch === undefined &&
3860-
this.storage.retryOptions.idempotencyStrategy ===
3861-
IdempotencyStrategy.RetryConditional) ||
3862-
this.storage.retryOptions.idempotencyStrategy ===
3863-
IdempotencyStrategy.RetryNever
3875+
!this.shouldRetryBasedOnPreconditionAndIdempotencyStrat(
3876+
options?.preconditionOpts
3877+
)
38643878
) {
38653879
retryOptions.autoRetry = false;
38663880
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.