Skip to content

Commit

Permalink
Merge pull request #2196 from jpd236/retry-api
Browse files Browse the repository at this point in the history
Retry more Google API failures.
  • Loading branch information
ebroder authored Jul 1, 2024
2 parents f36e3c2 + 2749f40 commit 48b2379
Show file tree
Hide file tree
Showing 3 changed files with 1,287 additions and 2,152 deletions.
27 changes: 24 additions & 3 deletions imports/server/googleClientRefresher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { people_v1 } from "@googleapis/people";
import { people } from "@googleapis/people";
import type { script_v1 } from "@googleapis/script";
import { script } from "@googleapis/script";
import type { RetryConfig } from "gaxios";
import type { SettingType } from "../lib/models/Settings";
import Settings from "../lib/models/Settings";

Expand All @@ -32,12 +33,19 @@ class GoogleClientRefresher {

private oauthCredentialCursor: Mongo.Cursor<SettingType>;

private retryConfig: RetryConfig;

constructor() {
this.drive = undefined;
this.oauthClient = undefined;
this.oauthConfig = undefined;
this.oauthRefreshToken = undefined;

this.retryConfig = {
// Retry POST failures as well, since most APIs use POST requests under the covers.
httpMethodsToRetry: ["GET", "PUT", "HEAD", "OPTIONS", "DELETE", "POST"],
};

// Watch for config changes, and refresh the gdrive instance if anything changes
this.oauthConfigCursor = ServiceConfiguration.configurations.find({
service: "google",
Expand Down Expand Up @@ -97,13 +105,26 @@ class GoogleClientRefresher {
});

// Construct the clients, using that OAuth2 client.
this.drive = drive({ version: "v3", auth: this.oauthClient });
this.drive = drive({
version: "v3",
auth: this.oauthClient,
retryConfig: this.retryConfig,
});
this.driveactivity = driveactivity({
version: "v2",
auth: this.oauthClient,
retryConfig: this.retryConfig,
});
this.script = script({
version: "v1",
auth: this.oauthClient,
retryConfig: this.retryConfig,
});
this.people = people({
version: "v1",
auth: this.oauthClient,
retryConfig: this.retryConfig,
});
this.script = script({ version: "v1", auth: this.oauthClient });
this.people = people({ version: "v1", auth: this.oauthClient });
}
}

Expand Down
Loading

0 comments on commit 48b2379

Please sign in to comment.