Skip to content

Commit

Permalink
wait on failure instead of retrying immediately (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks authored Apr 10, 2024
1 parent b9f5be1 commit 9192fe5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { lightBlock } from "@/utils/lightBlock";
import { LightBlock } from "@/models/lightstreamer";
import { logger } from "@/utils/logger";
import { RpcRequestError } from "@ironfish/sdk";
import { wait } from "@/utils/wait";

function getCachePath(): string {
if (process.env["CACHE_PATH"] && process.env["CACHE_FOLDER"]) {
Expand Down Expand Up @@ -58,6 +59,7 @@ export class LightBlockCache {
logger.warn("Rolling head back to rebuild cache.");
await this.rollbackHead();
}
wait(10000);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import zlib from "zlib";
import { LightBlockCache, lightBlockCache } from "@/cache";
import { LightBlock } from "@/models/lightstreamer";
import { logger } from "@/utils/logger";
import { wait } from "@/utils/wait";

class UploadError extends Error {}

Expand Down Expand Up @@ -87,6 +88,7 @@ export class LightBlockUpload {
await this.uploadInner();
} catch (error) {
logger.error(`Upload failed, will retry. Error: ${error}`);
wait(10000);
}
}
}
Expand Down Expand Up @@ -179,7 +181,7 @@ export class LightBlockUpload {
`hours since last upload: ${hoursSinceLastUpload.toFixed(2)}/` +
`${this.maxUploadLagMs / (1000 * 60 * 60)}, waiting...`,
);
await this.wait();
await wait();
continue;
}

Expand Down Expand Up @@ -272,10 +274,6 @@ export class LightBlockUpload {
return (bytes / 1024 / 1024).toFixed(4);
}

private async wait(ms = 60000): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, ms));
}

async uploadFile(
prefix: string,
fileName: string,
Expand Down
3 changes: 3 additions & 0 deletions src/utils/wait.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function wait(ms = 60000): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, ms));
}

0 comments on commit 9192fe5

Please sign in to comment.