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; key: T;
date: string; date: string;
}) { }) {
const maxRetries = 3; // Maximum number of retries const aggregatesFrom = (await fromDatabase.getAggregates({ key, date })).map(
let retryCount = 0; (aggregateWithoutKey) => ({ ...aggregateWithoutKey, key })
);
while (retryCount < maxRetries) { await toDatabase.insertAggregates(aggregatesFrom);
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"]; 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"); console.error("Dates should be in YYYY-MM-DD format");
process.exit(1); process.exit(1);
} }
for (let date = startDate; date <= endDate; date = nextDate(date)) {
while (retryCount < maxRetries) { // const symbols = await stockDatabaseClickhouse.getSymbols({ date });
try { for (const symbol of symbols) {
// ... rest of the code remains unchanged console.log(date, symbol);
const keys = await optionContractDatabaseClickhouse.getKeys({
await run(); key: { symbol },
} catch (error) { date,
console.warn(`Error occurred: ${error}. Retrying...`); });
retryCount++; for (const key of keys) {
const delay = Mathe.pow(2, retryCount) * 1000; // Exponential backoff strategy // console.log(date, symbol, key.expirationDate, key.strike, key.type);
console.warn(`Retry count: ${retryCount}, Delay: ${delay}ms`); await syncAggregates({
await new Promise((resolve) => setTimeout(resolve, delay)); fromDatabase: optionContractDatabaseClickhouse,
toDatabase: optionContractDatabaseLmdbx,
key,
date,
});
}
} }
} }
if (retryCount === maxRetries) {
console.error(`Failed to sync aggregates after ${maxRetries} retries.`);
}
} }
await run();

Loading…
Cancel
Save