Skip to content

Commit

Permalink
fix: idle if data is not available (#84)
Browse files Browse the repository at this point in the history
* fix: idle if next data item is not available

* fix: improved logging
  • Loading branch information
troykessler authored Oct 19, 2023
1 parent da043cc commit afade99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion common/protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
isStorageBalanceLow,
} from "./methods";
import { ICacheProvider, IMetrics, IRuntime } from "./types";
import { standardizeError } from "./utils";
import { IDLE_TIME, sleep, standardizeError } from "./utils";
import { SupportedChains } from "@kyvejs/sdk/dist/constants";
import { storageProviderFactory } from "./reactors/storageProviders";
import { compressionFactory } from "./reactors/compression";
Expand Down Expand Up @@ -317,6 +317,11 @@ export class Validator {
process.exit(1);
}

// until data is not available we wait and idle
while (!(await this.isDataAvailable())) {
await sleep(IDLE_TIME);
}

if (!(await this.isDataAvailable())) {
process.exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions common/protocol/src/methods/checks/isDataAvailable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export async function isDataAvailable(this: Validator): Promise<boolean> {

return true;
} catch (err) {
this.logger.fatal(`Data not available. Exiting ...`);
this.logger.fatal(standardizeError(err));
this.logger.warn(`Data not available for next key. Retrying in 60s ...`);
this.logger.debug(standardizeError(err));

return false;
}
Expand Down

0 comments on commit afade99

Please sign in to comment.