diff --git a/src/App/backend/services/sqldb_service.py b/src/App/backend/services/sqldb_service.py index be1c7b358..4368e4721 100644 --- a/src/App/backend/services/sqldb_service.py +++ b/src/App/backend/services/sqldb_service.py @@ -8,6 +8,8 @@ from backend.common.config import config +import time + load_dotenv() driver = config.ODBC_DRIVER @@ -33,33 +35,47 @@ def dict_cursor(cursor): def get_connection(): - try: - credential = DefaultAzureCredential(managed_identity_client_id=mid_id) + max_retries = 5 + retry_delay = 2 - token_bytes = credential.get_token( - "https://database.windows.net/.default" - ).token.encode("utf-16-LE") - token_struct = struct.pack( - f" str: diff --git a/src/App/frontend/src/api/api.ts b/src/App/frontend/src/api/api.ts index 1cd6442c3..6245ba819 100644 --- a/src/App/frontend/src/api/api.ts +++ b/src/App/frontend/src/api/api.ts @@ -42,20 +42,33 @@ export const getpbi = async (): Promise => { return ''; } +const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); + export const getUsers = async (): Promise => { - try { - const response = await fetch('/api/users'); - if (!response.ok) { - throw new Error(`Failed to fetch users: ${response.statusText}`); + const maxRetries = 1; + for (let attempt = 0; attempt <= maxRetries; attempt++) { + try { + const response = await fetch('/api/users', { + signal: AbortSignal.timeout(60000) + }); + if (!response.ok) { + throw new Error(`Failed to fetch users: ${response.statusText}`); + } + const data: User[] = await response.json(); + console.log('Fetched users:', data); + return data; + } catch (error) { + if (attempt < maxRetries && + error instanceof Error) { + console.warn(`Retrying fetch users... (retry ${attempt + 1}/${maxRetries})`); + await sleep(5000); // Simple 5 second delay + } else { + console.error('Error fetching users:', error); + return []; + } } - const data: User[] = await response.json(); - console.log('Fetched users:', data); - return data; - } catch (error) { - console.error('Error fetching users:', error); - return []; - // throw error; } + return []; }; // export const fetchChatHistoryInit = async (): Promise => {