From ed0333e00236ef4e6ed86158afe2618be967e9de Mon Sep 17 00:00:00 2001 From: SeungGwa123 Date: Sun, 1 Dec 2024 22:09:23 +0900 Subject: [PATCH] test: loadbalancing test logic fix --- nginx.conf | 3 +- packages/server/src/upbit/chart.service.ts | 49 +++++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/nginx.conf b/nginx.conf index fbee75e5..75748c2e 100644 --- a/nginx.conf +++ b/nginx.conf @@ -12,8 +12,7 @@ http { server 223.130.134.167:3000 weight=8 max_fails=3 fail_timeout=30s; server 223.130.130.192:3000 weight=8 max_fails=3 fail_timeout=30s; server 211.188.59.137:3000 weight=8 max_fails=3 fail_timeout=30s; - - server 124.28.132.80:7999 weight=80 max_fails=3 fail_timeout=30s; + keepalive 300; keepalive_requests 1000; keepalive_timeout 75s; diff --git a/packages/server/src/upbit/chart.service.ts b/packages/server/src/upbit/chart.service.ts index 7ab95054..27def79e 100644 --- a/packages/server/src/upbit/chart.service.ts +++ b/packages/server/src/upbit/chart.service.ts @@ -95,33 +95,32 @@ export class ChartService implements OnModuleInit { : `${baseUrl}?${query}`; } - async waitForTransactionOrder(key, maxRetries = 1000): Promise { + async waitForTransactionOrder(key, maxRetries = 1000, retryDelay = 10): Promise { let retryCount = 0; - - return new Promise(async (resolve, reject) => { - const check = async () => { - try { - const dbData = await this.redisRepository.getChartDate(key); - if (dbData.length === 200) { - return resolve(dbData); - } - const queueSize = this.upbitApiQueue.length; - if ( - queueSize < UPBIT_REQUEST_SIZE || - this.upbitApiQueue[queueSize - 1] - Date.now() < -ONE_SECOND - ) { - return resolve(false); - } - if (retryCount++ >= maxRetries) { - return reject(new Error('Timeout waiting for transaction order')); - } - setTimeout(check, 10); - } catch (error) { - reject(error); + + const checkTransaction = async () => { + try { + const dbData = await this.redisRepository.getChartDate(key); + if (dbData.length === 200) { + return dbData; + } + const queueSize = this.upbitApiQueue.length; + if ( + queueSize < UPBIT_REQUEST_SIZE || + this.upbitApiQueue[queueSize - 1] - Date.now() < -ONE_SECOND + ) { + return false; } - }; - check(); - }); + if (retryCount++ >= maxRetries) { + throw new Error('Timeout waiting for transaction order'); + } + return new Promise((resolve) => setTimeout(() => resolve(checkTransaction()), retryDelay)); + } catch (error) { + throw error; + } + }; + + return checkTransaction(); } async saveChartData(candles, type, minute) { try {