creación de scheduler.json para ejecución de servicio

This commit is contained in:
George committed 2026-08-04 09:34:44 -05:00
1 parent 839aad698d
commit 1c39f6f45f
11 files changed
+112 -400

No files matched your search

+9 -8
View File
@@ -3,10 +3,10 @@ from pathlib import Path
from datetime import datetime, timedelta
DB_PATH = Path(__file__).parent / "fallas_descarga.db"
# ============================================================================
def _conn():
return sqlite3.connect(str(DB_PATH))
# ============================================================================
def init_db():
with _conn() as conn:
conn.execute("""
@@ -22,7 +22,7 @@ def init_db():
fecha_ultimo TEXT NOT NULL
)
""")
# ============================================================================
def _calcular_proximo_intento(intentos):
if intentos >= 20:
return None
@@ -43,7 +43,7 @@ def _calcular_proximo_intento(intentos):
else:
delta = timedelta(hours=12)
return (datetime.now() + delta).isoformat()
# ============================================================================
def registrar_falla(docentry, ruc, tipo_cpe, serie, numero, error, intentos=None):
ahora = datetime.now().isoformat()
if intentos is None:
@@ -59,11 +59,11 @@ def registrar_falla(docentry, ruc, tipo_cpe, serie, numero, error, intentos=None
(docentry, ruc, tipo, serie, numero, error, intentos, proximo_intento, fecha_ultimo)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (docentry, ruc, tipo_cpe, serie, numero, str(error)[:200], intentos, proximo, ahora))
# ============================================================================
def eliminar_falla(docentry):
with _conn() as conn:
conn.execute("DELETE FROM fallas WHERE docentry = ?", (docentry,))
# ============================================================================
def obtener_fallas_pendientes() -> list[dict]:
ahora = datetime.now().isoformat()
with _conn() as conn:
@@ -75,12 +75,13 @@ def obtener_fallas_pendientes() -> list[dict]:
ORDER BY intentos ASC, fecha_ultimo ASC
""", (ahora,))
return [dict(row) for row in cursor.fetchall()]
# ============================================================================
def obtener_docentries_falla() -> set[int]:
with _conn() as conn:
cursor = conn.execute("SELECT docentry FROM fallas")
return {row[0] for row in cursor.fetchall()}
# ============================================================================
def total_fallas() -> int:
with _conn() as conn:
return conn.execute("SELECT COUNT(*) FROM fallas").fetchone()[0]
# ============================================================================