Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait on failure instead of retrying immediately #78

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
Loading