commons-metrics 0.0.25__tar.gz → 0.0.27__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.27}/PKG-INFO +1 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/__init__.py +1 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/database.py +24 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/repositories.py +4 -15
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics.egg-info/PKG-INFO +1 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/setup.py +1 -1
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/LICENSE +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/README.md +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/azure_devops_client.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/cache_manager.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/commons_repos_client.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/date_utils.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/github_api_client.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/s3_file_manager.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/text_simplifier.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/update_design_components.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/util.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics/variable_finder.py +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics.egg-info/SOURCES.txt +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics.egg-info/dependency_links.txt +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics.egg-info/requires.txt +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/commons_metrics.egg-info/top_level.txt +0 -0
- {commons_metrics-0.0.25 → commons_metrics-0.0.27}/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.27'
|
|
@@ -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
|
|
@@ -144,18 +144,11 @@ class ComponentRepository:
|
|
|
144
144
|
cursor.close()
|
|
145
145
|
|
|
146
146
|
def get_or_create_current_month_date(self) -> int:
|
|
147
|
-
"""
|
|
148
|
-
Obtiene el ID de la fecha del mes actual en measurement_systems_history.
|
|
149
|
-
Si no existe, crea un registro con la fecha de hoy.
|
|
150
|
-
|
|
151
|
-
Returns:
|
|
152
|
-
int: ID del registro de fecha
|
|
153
|
-
"""
|
|
154
147
|
cursor = None
|
|
155
148
|
try:
|
|
149
|
+
self.db.ensure_connection()
|
|
156
150
|
cursor = self.db.connection.cursor()
|
|
157
|
-
|
|
158
|
-
# Buscar si existe un registro del mes actual
|
|
151
|
+
|
|
159
152
|
query_select = """
|
|
160
153
|
SELECT id
|
|
161
154
|
FROM schmetrc.measurement_systems_history
|
|
@@ -165,14 +158,11 @@ class ComponentRepository:
|
|
|
165
158
|
"""
|
|
166
159
|
cursor.execute(query_select)
|
|
167
160
|
result = cursor.fetchone()
|
|
168
|
-
|
|
161
|
+
|
|
169
162
|
if result:
|
|
170
|
-
# Ya existe un registro del mes actual
|
|
171
163
|
date_id = result[0]
|
|
172
|
-
print(f" ℹ️ Usando fecha existente del mes actual (ID: {date_id})")
|
|
173
164
|
return date_id
|
|
174
165
|
else:
|
|
175
|
-
# No existe, crear uno nuevo con la fecha de hoy
|
|
176
166
|
query_insert = """
|
|
177
167
|
INSERT INTO schmetrc.measurement_systems_history (date)
|
|
178
168
|
VALUES (CURRENT_DATE)
|
|
@@ -181,9 +171,8 @@ class ComponentRepository:
|
|
|
181
171
|
cursor.execute(query_insert)
|
|
182
172
|
date_id = cursor.fetchone()[0]
|
|
183
173
|
self.db.commit_transaction()
|
|
184
|
-
print(f" ✅ Creado nuevo registro de fecha (ID: {date_id})")
|
|
185
174
|
return date_id
|
|
186
|
-
|
|
175
|
+
|
|
187
176
|
except Exception as e:
|
|
188
177
|
self.db.rollback_transaction()
|
|
189
178
|
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.27',
|
|
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.27}/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.27}/commons_metrics.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|