33
44import subprocess
55import sys
6+ from datetime import datetime , timezone
67from pathlib import Path
7- from datetime import datetime
88
99# Orden de ejecución del pipeline
1010SCRIPTS = [
1616]
1717
1818
19+ def now_utc () -> str :
20+ return datetime .now (timezone .utc ).isoformat (timespec = "seconds" )
21+
22+
1923def run_script (script : Path , root : Path ) -> int :
2024 print (f"\n >>> Ejecutando { script .name } " )
2125 result = subprocess .run (
@@ -29,44 +33,46 @@ def run_script(script: Path, root: Path) -> int:
2933def main () -> int :
3034 base = Path (__file__ ).resolve ().parent
3135 root = base .parent
36+ started_at = datetime .now (timezone .utc )
3237
3338 print ("===================================" )
3439 print ("Demographic Dataset Pipeline" )
35- print ("Inicio:" , datetime . utcnow (). isoformat (), "UTC" )
40+ print ("Inicio:" , now_utc (), "UTC" )
3641 print ("Python:" , sys .version .split ()[0 ])
42+ print ("Raíz del proyecto:" , root )
3743 print ("===================================\n " )
3844
39- failures = []
40-
4145 for name in SCRIPTS :
4246 script = base / name
4347
4448 if not script .exists ():
4549 print (f"ERROR: no se encontró el script { script } " , file = sys .stderr )
46- failures .append (name )
47- continue
50+ return 1
4851
4952 code = run_script (script , root )
5053
5154 if code != 0 :
52- print (f"ERROR: fallo en { script .name } con código { code } " , file = sys .stderr )
53- failures .append (name )
55+ print ("\n ===================================" )
56+ print (f"Pipeline interrumpido por error en { script .name } ." , file = sys .stderr )
57+ print (f"Código de salida: { code } " , file = sys .stderr )
58+ print ("Fin:" , now_utc (), "UTC" , file = sys .stderr )
59+ print ("===================================" )
60+ return code
5461
55- print ("\n ===================================" )
56-
57- if failures :
58- print ("Pipeline finalizado con errores." )
59- print ("Scripts con fallo:" )
60- for f in failures :
61- print (f" - { f } " )
62- return 1
62+ finished_at = datetime .now (timezone .utc )
63+ duration = finished_at - started_at
6364
65+ print ("\n ===================================" )
6466 print ("Pipeline completado correctamente." )
65- print ("Fin:" , datetime .utcnow ().isoformat (), "UTC" )
67+ print ("Fin:" , now_utc (), "UTC" )
68+ print ("Duración total:" , duration )
6669 print ("===================================" )
67-
6870 return 0
6971
7072
7173if __name__ == "__main__" :
72- raise SystemExit (main ())
74+ try :
75+ raise SystemExit (main ())
76+ except KeyboardInterrupt :
77+ print ("\n ERROR: ejecución interrumpida por el usuario." , file = sys .stderr )
78+ raise SystemExit (130 )
0 commit comments