Skip to content

Commit 9192fe5

Browse files
authored
wait on failure instead of retrying immediately (#78)
1 parent b9f5be1 commit 9192fe5

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/cache/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { lightBlock } from "@/utils/lightBlock";
88
import { LightBlock } from "@/models/lightstreamer";
99
import { logger } from "@/utils/logger";
1010
import { RpcRequestError } from "@ironfish/sdk";
11+
import { wait } from "@/utils/wait";
1112

1213
function getCachePath(): string {
1314
if (process.env["CACHE_PATH"] && process.env["CACHE_FOLDER"]) {
@@ -58,6 +59,7 @@ export class LightBlockCache {
5859
logger.warn("Rolling head back to rebuild cache.");
5960
await this.rollbackHead();
6061
}
62+
wait(10000);
6163
}
6264
}
6365
}

src/upload/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import zlib from "zlib";
1010
import { LightBlockCache, lightBlockCache } from "@/cache";
1111
import { LightBlock } from "@/models/lightstreamer";
1212
import { logger } from "@/utils/logger";
13+
import { wait } from "@/utils/wait";
1314

1415
class UploadError extends Error {}
1516

@@ -87,6 +88,7 @@ export class LightBlockUpload {
8788
await this.uploadInner();
8889
} catch (error) {
8990
logger.error(`Upload failed, will retry. Error: ${error}`);
91+
wait(10000);
9092
}
9193
}
9294
}
@@ -179,7 +181,7 @@ export class LightBlockUpload {
179181
`hours since last upload: ${hoursSinceLastUpload.toFixed(2)}/` +
180182
`${this.maxUploadLagMs / (1000 * 60 * 60)}, waiting...`,
181183
);
182-
await this.wait();
184+
await wait();
183185
continue;
184186
}
185187

@@ -272,10 +274,6 @@ export class LightBlockUpload {
272274
return (bytes / 1024 / 1024).toFixed(4);
273275
}
274276

275-
private async wait(ms = 60000): Promise<void> {
276-
await new Promise((resolve) => setTimeout(resolve, ms));
277-
}
278-
279277
async uploadFile(
280278
prefix: string,
281279
fileName: string,

src/utils/wait.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function wait(ms = 60000): Promise<void> {
2+
await new Promise((resolve) => setTimeout(resolve, ms));
3+
}

0 commit comments

Comments
 (0)