Revert "feat: Implement retry mechanism for clickhouse timeout errors with exponential backoff strategy in `clickhouse-to-lmdbx.ts` script"

This reverts commit c749321fe9.
main
avraham 9 months ago
parent c749321fe9
commit cfb207aae8

@ -16,27 +16,10 @@ async function syncAggregates<T>({
key: T;
date: string;
}) {
const maxRetries = 3; // Maximum number of retries
let retryCount = 0;
while (retryCount < maxRetries) {
try {
const aggregatesFrom = (await fromDatabase.getAggregates({ key, date })).map(
(aggregateWithoutKey) => ({ ...aggregateWithoutKey, key })
);
await toDatabase.insertAggregates(aggregatesFrom);
break; // Exit the loop if successful
} catch (error) {
retryCount++;
const delay = Math.pow(2, retryCount) * 1000; // Exponential backoff strategy
console.warn(`Retrying due to error: ${error}. Retry count: ${retryCount}, Delay: ${delay}ms`);
await new Promise((resolve) => setTimeout(resolve, delay));
}
}
if (retryCount === maxRetries) {
console.error(`Failed to sync aggregates after ${maxRetries} retries.`);
}
}
const symbols = ["AMD", "AAPL", "MSFT", "GOOGL", "NFLX", "NVDA"];
@ -49,22 +32,25 @@ async function run() {
console.error("Dates should be in YYYY-MM-DD format");
process.exit(1);
}
while (retryCount < maxRetries) {
try {
// ... rest of the code remains unchanged
await run();
} catch (error) {
console.warn(`Error occurred: ${error}. Retrying...`);
retryCount++;
const delay = Mathe.pow(2, retryCount) * 1000; // Exponential backoff strategy
console.warn(`Retry count: ${retryCount}, Delay: ${delay}ms`);
await new Promise((resolve) => setTimeout(resolve, delay));
for (let date = startDate; date <= endDate; date = nextDate(date)) {
// const symbols = await stockDatabaseClickhouse.getSymbols({ date });
for (const symbol of symbols) {
console.log(date, symbol);
const keys = await optionContractDatabaseClickhouse.getKeys({
key: { symbol },
date,
});
for (const key of keys) {
// console.log(date, symbol, key.expirationDate, key.strike, key.type);
await syncAggregates({
fromDatabase: optionContractDatabaseClickhouse,
toDatabase: optionContractDatabaseLmdbx,
key,
date,
});
}
}
if (retryCount === maxRetries) {
console.error(`Failed to sync aggregates after ${maxRetries} retries.`);
}
}
await run();

Loading…
Cancel
Save