Skip to content

Commit b6be53c

Browse files
committed
Add retry to most requests made by SyncManager
1 parent 53651f5 commit b6be53c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/sync-manager.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ export default class SyncManager {
146146
path: `${this.vault.configDir}/${MANIFEST_FILE_NAME}`,
147147
content: "",
148148
message: "First sync",
149+
retry: true,
149150
});
150151
// Now get the repo content again cause we know for sure it will return a
151152
// valid sha that we can use to create the first sync commit.
152-
res = await this.client.getRepoContent();
153+
res = await this.client.getRepoContent({ retry: true });
153154
files = res.files;
154155
treeSha = res.sha;
155156
}
@@ -333,7 +334,9 @@ export default class SyncManager {
333334

334335
private async syncImpl() {
335336
await this.logger.info("Starting sync");
336-
const { files, sha: treeSha } = await this.client.getRepoContent();
337+
const { files, sha: treeSha } = await this.client.getRepoContent({
338+
retry: true,
339+
});
337340
const manifest = files[`${this.vault.configDir}/${MANIFEST_FILE_NAME}`];
338341

339342
if (manifest === undefined) {
@@ -539,6 +542,8 @@ export default class SyncManager {
539542
await (async () => {
540543
const res = await this.client.getBlob({
541544
sha: filesMetadata[filePath].sha!,
545+
retry: true,
546+
maxRetries: 1,
542547
});
543548
return decodeBase64String(res.content);
544549
})(),
@@ -762,6 +767,8 @@ export default class SyncManager {
762767
const buffer = await this.vault.adapter.readBinary(filePath);
763768
const { sha } = await this.client.createBlob({
764769
content: arrayBufferToBase64(buffer),
770+
retry: true,
771+
maxRetries: 3,
765772
});
766773
treeFiles[filePath].sha = sha;
767774
// Can't have both sha and content set, so we delete it
@@ -782,9 +789,12 @@ export default class SyncManager {
782789
),
783790
base_tree: baseTreeSha,
784791
};
785-
const newTreeSha = await this.client.createTree({ tree: newTree });
792+
const newTreeSha = await this.client.createTree({
793+
tree: newTree,
794+
retry: true,
795+
});
786796

787-
const branchHeadSha = await this.client.getBranchHeadSha();
797+
const branchHeadSha = await this.client.getBranchHeadSha({ retry: true });
788798

789799
const commitSha = await this.client.createCommit({
790800
// TODO: Make this configurable or find a nicer commit message
@@ -793,7 +803,7 @@ export default class SyncManager {
793803
parent: branchHeadSha,
794804
});
795805

796-
await this.client.updateBranchHead({ sha: commitSha });
806+
await this.client.updateBranchHead({ sha: commitSha, retry: true });
797807

798808
// Update the local content of all files that had conflicts we resolved
799809
await Promise.all(
@@ -820,7 +830,7 @@ export default class SyncManager {
820830
// File already exists and has the same SHA, no need to download it again.
821831
return;
822832
}
823-
const blob = await this.client.getBlob({ sha: file.sha });
833+
const blob = await this.client.getBlob({ sha: file.sha, retry: true });
824834
const normalizedPath = normalizePath(file.path);
825835
const fileFolder = normalizePath(
826836
normalizedPath.split("/").slice(0, -1).join("/"),

0 commit comments

Comments
 (0)