fix flag elab
This commit is contained in:
@@ -10,7 +10,7 @@ import asyncio
|
|||||||
# Import custom modules for configuration and database connection
|
# Import custom modules for configuration and database connection
|
||||||
from utils.config import loader_matlab_elab as setting
|
from utils.config import loader_matlab_elab as setting
|
||||||
from utils.database import WorkflowFlags
|
from utils.database import WorkflowFlags
|
||||||
from utils.database.action_query import get_tool_info
|
from utils.database.action_query import get_tool_info, check_flag_elab
|
||||||
from utils.csv.loaders import get_next_csv_atomic
|
from utils.csv.loaders import get_next_csv_atomic
|
||||||
from utils.orchestrator_utils import run_orchestrator, worker_context
|
from utils.orchestrator_utils import run_orchestrator, worker_context
|
||||||
from utils.database.loader_action import update_status, unlock
|
from utils.database.loader_action import update_status, unlock
|
||||||
@@ -47,6 +47,7 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
logger.info("Inizio elaborazione")
|
logger.info("Inizio elaborazione")
|
||||||
|
if not await check_flag_elab(pool):
|
||||||
record = await get_next_csv_atomic(pool, cfg.dbrectable, WorkflowFlags.DATA_LOADED, WorkflowFlags.DATA_ELABORATED)
|
record = await get_next_csv_atomic(pool, cfg.dbrectable, WorkflowFlags.DATA_LOADED, WorkflowFlags.DATA_ELABORATED)
|
||||||
if record:
|
if record:
|
||||||
rec_id, _, tool_type, unit_name, tool_name = [x.lower().replace(" ", "_") if isinstance(x, str) else x for x in record]
|
rec_id, _, tool_type, unit_name, tool_name = [x.lower().replace(" ", "_") if isinstance(x, str) else x for x in record]
|
||||||
@@ -103,6 +104,9 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
|||||||
else:
|
else:
|
||||||
logger.info("Nessun record disponibile")
|
logger.info("Nessun record disponibile")
|
||||||
await asyncio.sleep(NO_RECORD_SLEEP)
|
await asyncio.sleep(NO_RECORD_SLEEP)
|
||||||
|
else:
|
||||||
|
logger.info("Flag fermo elaborazione attivato")
|
||||||
|
await asyncio.sleep(NO_RECORD_SLEEP)
|
||||||
|
|
||||||
except Exception as e: # pylint: disable=broad-except
|
except Exception as e: # pylint: disable=broad-except
|
||||||
logger.error("Errore durante l'esecuzione: %s", e, exc_info=debug_mode)
|
logger.error("Errore durante l'esecuzione: %s", e, exc_info=debug_mode)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ logger = logging.getLogger(__name__)
|
|||||||
class DummySha256Authorizer(DummyAuthorizer):
|
class DummySha256Authorizer(DummyAuthorizer):
|
||||||
"""Custom authorizer that uses SHA256 for password hashing and manages users from a database."""
|
"""Custom authorizer that uses SHA256 for password hashing and manages users from a database."""
|
||||||
|
|
||||||
def __init__(self: object, cfg: object) -> None:
|
def __init__(self: object, cfg: dict) -> None:
|
||||||
"""Initializes the authorizer, adds the admin user, and loads users from the database.
|
"""Initializes the authorizer, adds the admin user, and loads users from the database.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import asyncio
|
|||||||
from utils.config import loader_load_data as setting
|
from utils.config import loader_load_data as setting
|
||||||
from utils.database import WorkflowFlags
|
from utils.database import WorkflowFlags
|
||||||
from utils.csv.loaders import get_next_csv_atomic
|
from utils.csv.loaders import get_next_csv_atomic
|
||||||
from utils.database.action_query import check_flag_elab
|
|
||||||
from utils.orchestrator_utils import run_orchestrator, worker_context
|
from utils.orchestrator_utils import run_orchestrator, worker_context
|
||||||
|
|
||||||
# Initialize the logger for this module
|
# Initialize the logger for this module
|
||||||
@@ -24,7 +23,7 @@ CSV_PROCESSING_DELAY = 0.2
|
|||||||
NO_RECORD_SLEEP = 60
|
NO_RECORD_SLEEP = 60
|
||||||
|
|
||||||
|
|
||||||
async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
async def worker(worker_id: int, cfg: dict, pool: object) -> None:
|
||||||
"""Esegue il ciclo di lavoro per l'elaborazione dei file CSV.
|
"""Esegue il ciclo di lavoro per l'elaborazione dei file CSV.
|
||||||
|
|
||||||
Il worker preleva un record CSV dal database, ne elabora il contenuto
|
Il worker preleva un record CSV dal database, ne elabora il contenuto
|
||||||
@@ -32,7 +31,7 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
worker_id (int): L'ID univoco del worker.
|
worker_id (int): L'ID univoco del worker.
|
||||||
cfg (object): L'oggetto di configurazione.
|
cfg (dict): L'oggetto di configurazione.
|
||||||
pool (object): Il pool di connessioni al database.
|
pool (object): Il pool di connessioni al database.
|
||||||
"""
|
"""
|
||||||
# Imposta il context per questo worker
|
# Imposta il context per questo worker
|
||||||
@@ -43,7 +42,6 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
logger.info("Inizio elaborazione")
|
logger.info("Inizio elaborazione")
|
||||||
if not await check_flag_elab():
|
|
||||||
record = await get_next_csv_atomic(
|
record = await get_next_csv_atomic(
|
||||||
pool,
|
pool,
|
||||||
cfg.dbrectable,
|
cfg.dbrectable,
|
||||||
@@ -59,9 +57,6 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
|||||||
else:
|
else:
|
||||||
logger.info("Nessun record disponibile")
|
logger.info("Nessun record disponibile")
|
||||||
await asyncio.sleep(NO_RECORD_SLEEP)
|
await asyncio.sleep(NO_RECORD_SLEEP)
|
||||||
else:
|
|
||||||
logger.info("Flag fermo elaborazione attivato")
|
|
||||||
await asyncio.sleep(NO_RECORD_SLEEP)
|
|
||||||
|
|
||||||
except Exception as e: # pylint: disable=broad-except
|
except Exception as e: # pylint: disable=broad-except
|
||||||
logger.error("Errore durante l'esecuzione: %s", e, exc_info=1)
|
logger.error("Errore durante l'esecuzione: %s", e, exc_info=1)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ ELAB_PROCESSING_DELAY = 0.2
|
|||||||
NO_RECORD_SLEEP = 30
|
NO_RECORD_SLEEP = 30
|
||||||
|
|
||||||
|
|
||||||
async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
async def worker(worker_id: int, cfg: dict, pool: object) -> None:
|
||||||
"""Esegue il ciclo di lavoro per l'invio dei dati.
|
"""Esegue il ciclo di lavoro per l'invio dei dati.
|
||||||
|
|
||||||
Il worker preleva un record dal database che indica dati pronti per
|
Il worker preleva un record dal database che indica dati pronti per
|
||||||
@@ -37,7 +37,7 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
worker_id (int): L'ID univoco del worker.
|
worker_id (int): L'ID univoco del worker.
|
||||||
cfg (object): L'oggetto di configurazione.
|
cfg (dict): L'oggetto di configurazione.
|
||||||
pool (object): Il pool di connessioni al database.
|
pool (object): Il pool di connessioni al database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ async def check_flag_elab(pool: object) -> None:
|
|||||||
async with pool.acquire() as conn:
|
async with pool.acquire() as conn:
|
||||||
async with conn.cursor() as cur:
|
async with conn.cursor() as cur:
|
||||||
try:
|
try:
|
||||||
await cur.execute("SELECT ferma_elab from admin_panel")
|
await cur.execute("SELECT stop_elab from admin_panel")
|
||||||
results = await cur.fetchone()
|
results = await cur.fetchone()
|
||||||
return results[0]
|
return results[0]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user