se agrega scheduler.json para subir el proyecto a docker
This commit is contained in:
1 parent
cfb6e5ce52
commit
1356646abf
2 files changed
+52
-14
No files matched your search
@@ -12,21 +12,32 @@ from hana_manager import actualizar_documento_sap
|
|||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
HORARIOS = [
|
config = {}
|
||||||
(6, 30, 13, 15, 10, "rapido"), # 06:30 - 13:15 -> cada 10 segundos
|
|
||||||
(13, 15, 14, 0, 1800, "full"), # 13:15 - 14:00 -> cada 30 minutos
|
|
||||||
(14, 0, 17, 30, 10, "rapido"), # 14:00 - 17:30 -> cada 10 segundos
|
# ============================================================================
|
||||||
(17, 30, 21, 30, 1800, "full"), # 17:30 - 21:30 -> cada 30 minutos
|
def cargar_programacion() -> dict:
|
||||||
]
|
global config
|
||||||
|
with open("scheduler.json", "r", encoding="utf-8") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
data["HORARIOS"] = [tuple(h) for h in data["HORARIOS"]]
|
||||||
|
config = data
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def obtener_horarios() -> list:
|
||||||
|
return config.get("HORARIOS", [])
|
||||||
|
|
||||||
|
|
||||||
|
def obtener_dias_activos() -> list:
|
||||||
|
return config.get("DIAS_ACTIVOS", [])
|
||||||
|
|
||||||
# 0=lun, 1=mar, 2=mié, 3=jue, 4=vie, 5=sáb, 6=dom
|
|
||||||
DIAS_ACTIVOS = [0, 1, 2, 3, 4] # lun, mar, mie, jue, vie
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
def obtener_intervalo(dt: datetime) -> tuple[int, str] | None:
|
def obtener_intervalo(dt: datetime) -> tuple[int, str] | None:
|
||||||
minutos = dt.hour * 60 + dt.minute
|
minutos = dt.hour * 60 + dt.minute
|
||||||
|
|
||||||
for hi, mi, hf, mf, intervalo, modo in HORARIOS:
|
for hi, mi, hf, mf, intervalo, modo in obtener_horarios():
|
||||||
inicio = hi * 60 + mi
|
inicio = hi * 60 + mi
|
||||||
fin = hf * 60 + mf
|
fin = hf * 60 + mf
|
||||||
|
|
||||||
@@ -37,7 +48,13 @@ def obtener_intervalo(dt: datetime) -> tuple[int, str] | None:
|
|||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
def segundos_hasta_proximo_inicio(dt: datetime) -> int:
|
def segundos_hasta_proximo_inicio(dt: datetime) -> int:
|
||||||
inicio = dt.replace(hour=6, minute=30, second=0, microsecond=0)
|
horarios = obtener_horarios()
|
||||||
|
if horarios:
|
||||||
|
hi, mi = horarios[0][0], horarios[0][1]
|
||||||
|
else:
|
||||||
|
hi, mi = 6, 30
|
||||||
|
|
||||||
|
inicio = dt.replace(hour=hi, minute=mi, second=0, microsecond=0)
|
||||||
|
|
||||||
if dt >= inicio:
|
if dt >= inicio:
|
||||||
inicio += timedelta(days=1)
|
inicio += timedelta(days=1)
|
||||||
@@ -46,10 +63,14 @@ def segundos_hasta_proximo_inicio(dt: datetime) -> int:
|
|||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
def segundos_hasta_proximo_dia_activo(dt: datetime) -> int:
|
def segundos_hasta_proximo_dia_activo(dt: datetime) -> int:
|
||||||
|
horarios = obtener_horarios()
|
||||||
|
hi, mi = (horarios[0][0], horarios[0][1]) if horarios else (6, 30)
|
||||||
|
dias_activos = obtener_dias_activos()
|
||||||
|
|
||||||
for dias in range(1, 8):
|
for dias in range(1, 8):
|
||||||
prox = dt + timedelta(days=dias)
|
prox = dt + timedelta(days=dias)
|
||||||
if prox.weekday() in DIAS_ACTIVOS:
|
if prox.weekday() in dias_activos:
|
||||||
target = prox.replace(hour=6, minute=30, second=0, microsecond=0)
|
target = prox.replace(hour=hi, minute=mi, second=0, microsecond=0)
|
||||||
return int((target - dt).total_seconds())
|
return int((target - dt).total_seconds())
|
||||||
return 86400
|
return 86400
|
||||||
|
|
||||||
@@ -263,10 +284,12 @@ def procesar_todas_empresas(inicio_ciclo, modo):
|
|||||||
def main():
|
def main():
|
||||||
|
|
||||||
log_path = logger_utilities.setup_logger()
|
log_path = logger_utilities.setup_logger()
|
||||||
logger_utilities.limpiar_logs_antiguos(dias=7)
|
_ultima_limpieza = None
|
||||||
|
|
||||||
load_dotenv(dotenv_path=".env")
|
load_dotenv(dotenv_path=".env")
|
||||||
|
|
||||||
|
cargar_programacion()
|
||||||
|
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print("🚀 Demonio iniciado")
|
print("🚀 Demonio iniciado")
|
||||||
print(f"📄 Log guardado en: {log_path}")
|
print(f"📄 Log guardado en: {log_path}")
|
||||||
@@ -277,9 +300,15 @@ def main():
|
|||||||
|
|
||||||
inicio_ciclo = datetime.now()
|
inicio_ciclo = datetime.now()
|
||||||
|
|
||||||
|
cargar_programacion()
|
||||||
|
|
||||||
logger_utilities.rotar_log()
|
logger_utilities.rotar_log()
|
||||||
|
|
||||||
if inicio_ciclo.weekday() not in DIAS_ACTIVOS:
|
if _ultima_limpieza != inicio_ciclo.date():
|
||||||
|
logger_utilities.limpiar_logs_antiguos(dias=7)
|
||||||
|
_ultima_limpieza = inicio_ciclo.date()
|
||||||
|
|
||||||
|
if inicio_ciclo.weekday() not in obtener_dias_activos():
|
||||||
dormir = segundos_hasta_proximo_dia_activo(inicio_ciclo)
|
dormir = segundos_hasta_proximo_dia_activo(inicio_ciclo)
|
||||||
print(
|
print(
|
||||||
f"\n[{inicio_ciclo:%Y-%m-%d %H:%M:%S}] "
|
f"\n[{inicio_ciclo:%Y-%m-%d %H:%M:%S}] "
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"HORARIOS": [
|
||||||
|
[6, 30, 13, 15, 10, "rapido"],
|
||||||
|
[13, 15, 14, 0, 1800, "full"],
|
||||||
|
[14, 0, 17, 30, 10, "rapido"],
|
||||||
|
[17, 30, 21, 30, 1800, "full"]
|
||||||
|
],
|
||||||
|
"DIAS_ACTIVOS": [0, 1, 2, 3, 4]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user