commons-metrics 0.0.25__tar.gz → 0.0.26__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/PKG-INFO +1 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/__init__.py +1 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/database.py +24 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/repositories.py +8 -13
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics.egg-info/PKG-INFO +1 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/setup.py +1 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/LICENSE +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/README.md +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/azure_devops_client.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/cache_manager.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/commons_repos_client.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/date_utils.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/github_api_client.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/s3_file_manager.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/text_simplifier.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/update_design_components.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/util.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/variable_finder.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics.egg-info/SOURCES.txt +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics.egg-info/dependency_links.txt +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics.egg-info/requires.txt +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics.egg-info/top_level.txt +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.26}/setup.cfg +0 -0
|
@@ -12,4 +12,4 @@ from .text_simplifier import TextSimplifier
|
|
|
12
12
|
from .variable_finder import VariableFinder
|
|
13
13
|
|
|
14
14
|
__all__ = ['Util', 'DatabaseConnection', 'ComponentRepository', 'UpdateDesignSystemComponents', 'GitHubAPIClient', 'AzureDevOpsClient', 'S3FileManager', 'CacheManager', 'CommonsReposClient', 'DateUtils', 'TextSimplifier', 'VariableFinder']
|
|
15
|
-
__version__ = '0.0.
|
|
15
|
+
__version__ = '0.0.26'
|
|
@@ -10,6 +10,7 @@ class DatabaseConnection:
|
|
|
10
10
|
|
|
11
11
|
def __init__(self):
|
|
12
12
|
self.connection = None
|
|
13
|
+
self._credentials = None
|
|
13
14
|
|
|
14
15
|
def connect(self, credentials):
|
|
15
16
|
"""Establishes database connection using credentials"""
|
|
@@ -20,8 +21,14 @@ class DatabaseConnection:
|
|
|
20
21
|
database=credentials['dbname'],
|
|
21
22
|
user=credentials['username'],
|
|
22
23
|
password=credentials['password'],
|
|
23
|
-
connect_timeout=30
|
|
24
|
+
connect_timeout=30,
|
|
25
|
+
sslmode='require',
|
|
26
|
+
keepalives=1,
|
|
27
|
+
keepalives_idle=30,
|
|
28
|
+
keepalives_interval=10,
|
|
29
|
+
keepalives_count=5
|
|
24
30
|
)
|
|
31
|
+
self._credentials = credentials
|
|
25
32
|
except Exception as e:
|
|
26
33
|
raise Exception(f"Database connection error: {str(e)}")
|
|
27
34
|
|
|
@@ -40,6 +47,22 @@ class DatabaseConnection:
|
|
|
40
47
|
if self.connection and not self.connection.closed:
|
|
41
48
|
self.connection.rollback()
|
|
42
49
|
|
|
50
|
+
def ensure_connection(self):
|
|
51
|
+
"""Verifies connection is alive and reconnects if necessary"""
|
|
52
|
+
try:
|
|
53
|
+
if self.connection is None or self.connection.closed:
|
|
54
|
+
if self._credentials:
|
|
55
|
+
print("⚠️ Reconnecting to database...")
|
|
56
|
+
self.connect(self._credentials)
|
|
57
|
+
else:
|
|
58
|
+
raise Exception("Connection is closed and no credentials available for reconnection")
|
|
59
|
+
except Exception as e:
|
|
60
|
+
if self._credentials:
|
|
61
|
+
print(f"⚠️ Connection lost, attempting reconnection: {str(e)}")
|
|
62
|
+
self.connect(self._credentials)
|
|
63
|
+
else:
|
|
64
|
+
raise Exception(f"Cannot ensure connection: {str(e)}")
|
|
65
|
+
|
|
43
66
|
def get_connection_database_from_secret(secret_name: str, logger: str, aws_region: str) -> ComponentRepository:
|
|
44
67
|
"""
|
|
45
68
|
Retrieve connection database from AWS secrets manager
|
|
@@ -145,34 +145,30 @@ class ComponentRepository:
|
|
|
145
145
|
|
|
146
146
|
def get_or_create_current_month_date(self) -> int:
|
|
147
147
|
"""
|
|
148
|
-
Obtiene el ID de la fecha
|
|
149
|
-
Si no existe, crea un registro con
|
|
148
|
+
Obtiene el ID de la fecha de HOY en measurement_systems_history.
|
|
149
|
+
Si no existe, crea un registro con CURRENT_DATE y devuelve su ID.
|
|
150
150
|
|
|
151
151
|
Returns:
|
|
152
|
-
int: ID del registro de fecha
|
|
152
|
+
int: ID del registro de fecha de hoy
|
|
153
153
|
"""
|
|
154
154
|
cursor = None
|
|
155
155
|
try:
|
|
156
|
+
self.db.ensure_connection()
|
|
156
157
|
cursor = self.db.connection.cursor()
|
|
157
|
-
|
|
158
|
-
# Buscar si existe un registro del mes actual
|
|
158
|
+
|
|
159
159
|
query_select = """
|
|
160
160
|
SELECT id
|
|
161
161
|
FROM schmetrc.measurement_systems_history
|
|
162
|
-
WHERE
|
|
163
|
-
AND EXTRACT(MONTH FROM date) = EXTRACT(MONTH FROM CURRENT_DATE)
|
|
162
|
+
WHERE date = CURRENT_DATE
|
|
164
163
|
LIMIT 1
|
|
165
164
|
"""
|
|
166
165
|
cursor.execute(query_select)
|
|
167
166
|
result = cursor.fetchone()
|
|
168
|
-
|
|
167
|
+
|
|
169
168
|
if result:
|
|
170
|
-
# Ya existe un registro del mes actual
|
|
171
169
|
date_id = result[0]
|
|
172
|
-
print(f" ℹ️ Usando fecha existente del mes actual (ID: {date_id})")
|
|
173
170
|
return date_id
|
|
174
171
|
else:
|
|
175
|
-
# No existe, crear uno nuevo con la fecha de hoy
|
|
176
172
|
query_insert = """
|
|
177
173
|
INSERT INTO schmetrc.measurement_systems_history (date)
|
|
178
174
|
VALUES (CURRENT_DATE)
|
|
@@ -181,9 +177,8 @@ class ComponentRepository:
|
|
|
181
177
|
cursor.execute(query_insert)
|
|
182
178
|
date_id = cursor.fetchone()[0]
|
|
183
179
|
self.db.commit_transaction()
|
|
184
|
-
print(f" ✅ Creado nuevo registro de fecha (ID: {date_id})")
|
|
185
180
|
return date_id
|
|
186
|
-
|
|
181
|
+
|
|
187
182
|
except Exception as e:
|
|
188
183
|
self.db.rollback_transaction()
|
|
189
184
|
raise RuntimeError(f"Error getting or creating current month date: {str(e)}")
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='commons_metrics',
|
|
5
|
-
version='0.0.
|
|
5
|
+
version='0.0.26',
|
|
6
6
|
description='A simple library for basic statistical calculations',
|
|
7
7
|
#long_description=open('USAGE.md').read(),
|
|
8
8
|
#long_description_content_type='text/markdown',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics/update_design_components.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{commons_metrics-0.0.25 → commons_metrics-0.0.26}/commons_metrics.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|