Skip to content

Commit

Permalink
test: loadbalancing test logic fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungGwan123 committed Dec 1, 2024
1 parent 0c7cf56 commit ed0333e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
3 changes: 1 addition & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 24 additions & 25 deletions packages/server/src/upbit/chart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,32 @@ export class ChartService implements OnModuleInit {
: `${baseUrl}?${query}`;
}

async waitForTransactionOrder(key, maxRetries = 1000): Promise<any> {
async waitForTransactionOrder(key, maxRetries = 1000, retryDelay = 10): Promise<any> {
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 {
Expand Down

0 comments on commit ed0333e

Please sign in to comment.