AIdeaText commited on
Commit
92248a8
verified
1 Parent(s): 3323084

Update modules/database/database_init.py

Browse files
Files changed (1) hide show
  1. modules/database/database_init.py +19 -59
modules/database/database_init.py CHANGED
@@ -46,7 +46,8 @@ def get_container(container_name):
46
  containers_status = {
47
  "users": user_container is not None,
48
  "users_sessions": user_sessions_container is not None,
49
- "application_requests": application_requests_container is not None
 
50
  }
51
 
52
  logger.info(f"Estado actual de los contenedores: {containers_status}")
@@ -55,7 +56,8 @@ def get_container(container_name):
55
  containers = {
56
  "users": user_container,
57
  "users_sessions": user_sessions_container,
58
- "application_requests": application_requests_container
 
59
  }
60
 
61
  container = containers.get(container_name)
@@ -106,10 +108,10 @@ def get_container(container_name):
106
 
107
  def initialize_cosmos_sql_connection():
108
  """Inicializa la conexi贸n a Cosmos DB SQL API"""
109
- global cosmos_client, user_database, user_container, user_sessions_container, application_requests_container
110
 
111
  try:
112
- # Verificar conexi贸n existente
113
  if all([
114
  cosmos_client,
115
  user_database,
@@ -121,63 +123,21 @@ def initialize_cosmos_sql_connection():
121
  logger.debug("Todas las conexiones ya est谩n inicializadas")
122
  return True
123
 
124
- # Obtener credenciales
125
- cosmos_endpoint = os.environ.get("COSMOS_ENDPOINT")
126
- cosmos_key = os.environ.get("COSMOS_KEY")
127
-
128
- if not cosmos_endpoint or not cosmos_key:
129
- raise ValueError("COSMOS_ENDPOINT y COSMOS_KEY deben estar configurados")
130
 
131
- # Inicializar cliente y base de datos
132
- cosmos_client = CosmosClient(cosmos_endpoint, cosmos_key)
133
- user_database = cosmos_client.get_database_client("user_database")
134
-
135
- # Inicializar cada contenedor individualmente con verificaci贸n
136
- try:
137
- user_container = user_database.get_container_client("users")
138
- logger.info("Contenedor 'users' inicializado correctamente")
139
- except Exception as e:
140
- logger.error(f"Error inicializando contenedor 'users': {str(e)}")
141
- user_container = None
142
-
143
- try:
144
- user_sessions_container = user_database.get_container_client("users_sessions")
145
- logger.info("Contenedor 'users_sessions' inicializado correctamente")
146
- except Exception as e:
147
- logger.error(f"Error inicializando contenedor 'users_sessions': {str(e)}")
148
- user_sessions_container = None
149
-
150
- try:
151
- application_requests_container = user_database.get_container_client("application_requests")
152
- logger.info("Contenedor 'application_requests' inicializado correctamente")
153
- except Exception as e:
154
- logger.error(f"Error inicializando contenedor 'application_requests': {str(e)}")
155
- application_requests_container = None
156
-
157
- try:
158
- user_feedback_container = user_database.get_container_client("user_feedback_container")
159
- logger.info("Contenedor 'user_feedback_container' inicializado correctamente")
160
- except Exception as e:
161
- logger.error(f"Error inicializando contenedor 'user_feedback_container': {str(e)}")
162
- application_requests_container = None
163
-
164
- # Verificar el estado de los contenedores
165
- containers_status = {
166
- 'users': user_container is not None,
167
- 'users_sessions': user_sessions_container is not None,
168
- 'application_requests': application_requests_container is not None,
169
- 'user_feedback': user_feedback_container is not None
170
- }
171
-
172
- logger.info(f"Estado de los contenedores: {containers_status}")
173
 
174
- # Solo retornar True si todos los contenedores se inicializaron correctamente
175
- if all(containers_status.values()):
176
- logger.info("Todos los contenedores inicializados correctamente")
177
- return True
178
- else:
179
- logger.error("No se pudieron inicializar todos los contenedores")
180
- return False
181
 
182
  except Exception as e:
183
  logger.error(f"Error al conectar con Cosmos DB SQL API: {str(e)}")
 
46
  containers_status = {
47
  "users": user_container is not None,
48
  "users_sessions": user_sessions_container is not None,
49
+ "application_requests": application_requests_container is not None,
50
+ "user_feedback": application_user_feedback is not None,
51
  }
52
 
53
  logger.info(f"Estado actual de los contenedores: {containers_status}")
 
56
  containers = {
57
  "users": user_container,
58
  "users_sessions": user_sessions_container,
59
+ "application_requests": application_requests_container,
60
+ "user_feedback": user_feedback_container
61
  }
62
 
63
  container = containers.get(container_name)
 
108
 
109
  def initialize_cosmos_sql_connection():
110
  """Inicializa la conexi贸n a Cosmos DB SQL API"""
111
+ global cosmos_client, user_database, user_container, user_sessions_container, application_requests_container, user_feedback_container
112
 
113
  try:
114
+ # Verificar conexiones existentes
115
  if all([
116
  cosmos_client,
117
  user_database,
 
123
  logger.debug("Todas las conexiones ya est谩n inicializadas")
124
  return True
125
 
126
+ # ... c贸digo existente ...
 
 
 
 
 
127
 
128
+ # Inicializar contenedores
129
+ user_container = user_database.get_container_client("users")
130
+ user_sessions_container = user_database.get_container_client("users_sessions")
131
+ application_requests_container = user_database.get_container_client("application_requests")
132
+ user_feedback_container = user_database.get_container_client("user_feedback")
133
+
134
+ logger.info("Contenedores inicializados:")
135
+ logger.info(f"- users: {user_container is not None}")
136
+ logger.info(f"- users_sessions: {user_sessions_container is not None}")
137
+ logger.info(f"- application_requests: {application_requests_container is not None}")
138
+ logger.info(f"- user_feedback: {user_feedback_container is not None}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
+ return True
 
 
 
 
 
 
141
 
142
  except Exception as e:
143
  logger.error(f"Error al conectar con Cosmos DB SQL API: {str(e)}")