first commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
#from App import *
|
||||
#from requests import *
|
||||
from datetime import datetime, timedelta
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
|
||||
from App.Config.feduroConfig import FeduroConfig
|
||||
from App.Services.etl_service import *
|
||||
from App.Utils.notification_utils import send_whatsapp, build_message
|
||||
|
||||
#Iniciando variables para resumen y mensaje final
|
||||
|
||||
|
||||
|
||||
# Cargando configuración del proyecto
|
||||
configs = [
|
||||
# FeduroConfig(),
|
||||
PGConfig(),
|
||||
# CorripioConfig(),
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
#Iniciando proceso ETL para cada proyecto por reporte y cada fecha (últimos 3 días)
|
||||
for config in configs:
|
||||
summary = {
|
||||
"total": 0,
|
||||
"success": 0,
|
||||
"failed": [], # catastróficos
|
||||
"errors": [], # no bloqueantes
|
||||
"warnings": []
|
||||
}
|
||||
|
||||
warning_counter = defaultdict(int)
|
||||
warning_details = defaultdict(list)
|
||||
|
||||
start_time = datetime.now()
|
||||
|
||||
|
||||
print(f"\n🚀 Ejecutando proyecto: {config.project_name}")
|
||||
|
||||
for report in config.reports:
|
||||
|
||||
data_report = {
|
||||
'project_name': config.project_name,
|
||||
'report_name': report['ReportName'],
|
||||
'Table_Name': report['TableName'],
|
||||
'reportID': report['ReportID'],
|
||||
'FTP': report['FTP'],
|
||||
'SFTP': report['SFTP'],
|
||||
'SharePoint': report['SharePoint'],
|
||||
'N8N': report['N8N']
|
||||
}
|
||||
|
||||
for i in range(3):
|
||||
target_date_report = datetime.now() - timedelta(days=i)
|
||||
|
||||
print(f"Ejecutando ETL para {data_report['report_name']} - Fecha: {target_date_report.strftime('%Y-%m-%d')}")
|
||||
|
||||
result = run_etl(config, data_report, target_date_report)
|
||||
|
||||
summary["total"] += 1
|
||||
|
||||
if result["status"] == "SUCCESS":
|
||||
summary["success"] += 1
|
||||
|
||||
elif result["status"] == "FAILED":
|
||||
summary["failed"].append(f"{result['report']} ({target_date_report.strftime('%Y-%m-%d')}) → {result['message']}")
|
||||
|
||||
elif result["status"] == "COMPLETED_WITH_ERRORS":
|
||||
summary["errors"].append(
|
||||
f"{result['report']} ({target_date_report.strftime('%Y-%m-%d')}) → {result['message']}"
|
||||
)
|
||||
|
||||
elif result["status"] == "WARNING":
|
||||
|
||||
is_sunday = target_date_report.weekday() == 6
|
||||
is_no_data = "Sin datos" in result["message"]
|
||||
|
||||
# Ignorar solo domingos SIN datos
|
||||
if is_sunday and is_no_data:
|
||||
continue
|
||||
|
||||
key = result["report"]
|
||||
|
||||
warning_counter[key] += 1
|
||||
warning_details[key].append({
|
||||
"date": target_date_report.strftime('%Y-%m-%d'),
|
||||
"message": result["message"]
|
||||
})
|
||||
|
||||
for report, count in warning_counter.items():
|
||||
|
||||
messages = warning_details[report]
|
||||
|
||||
# Tomamos el mensaje base (todos son iguales normalmente)
|
||||
base_message = messages[0]["message"]
|
||||
|
||||
if count >= 3:
|
||||
summary["failed"].append(
|
||||
f"{report} → {base_message} ({count} días consecutivos)"
|
||||
)
|
||||
else:
|
||||
for m in messages:
|
||||
summary["warnings"].append(
|
||||
f"{report} ({m['date']}) → {m['message']}"
|
||||
)
|
||||
|
||||
end_time = datetime.now()
|
||||
duration = end_time - start_time
|
||||
|
||||
message = build_message(config.project_name, summary, duration)
|
||||
|
||||
print(message) # debug
|
||||
|
||||
|
||||
send_whatsapp(message)
|
||||
|
||||
print("end")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user