Compare commits
4 Commits
1a99b55dbb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 35527c89cd | |||
| 8cd5a21275 | |||
| 2d2668c92c | |||
| adfe2e7809 |
4
.vscode/setting.json
vendored
Normal file
4
.vscode/setting.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"flake8.args": ["--max-line-length=140"],
|
||||||
|
"python.linting.flake8Args": ["--config","flake8.cfg"]
|
||||||
|
}
|
||||||
@@ -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:
|
||||||
@@ -47,13 +47,14 @@ class DummySha256Authorizer(DummyAuthorizer):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for ftpuser, user_hash, virtpath, perm in cur.fetchall():
|
for ftpuser, user_hash, virtpath, perm in cur.fetchall():
|
||||||
self.add_user(ftpuser, user_hash, virtpath, perm)
|
|
||||||
# Create the user's directory if it does not exist.
|
# Create the user's directory if it does not exist.
|
||||||
try:
|
try:
|
||||||
Path(cfg.virtpath + ftpuser).mkdir(parents=True, exist_ok=True)
|
Path(cfg.virtpath + ftpuser).mkdir(parents=True, exist_ok=True)
|
||||||
|
self.add_user(ftpuser, user_hash, virtpath, perm)
|
||||||
except Exception as e: # pylint: disable=broad-except
|
except Exception as e: # pylint: disable=broad-except
|
||||||
self.responde(f"551 Error in create virtual user path: {e}")
|
self.responde(f"551 Error in create virtual user path: {e}")
|
||||||
|
|
||||||
|
|
||||||
def validate_authentication(
|
def validate_authentication(
|
||||||
self: object, username: str, password: str, handler: object
|
self: object, username: str, password: str, handler: object
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@@ -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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ def on_file_received(self: object, file: str) -> None:
|
|||||||
new_filename = f"{filename}_{timestamp}{fileExtension}"
|
new_filename = f"{filename}_{timestamp}{fileExtension}"
|
||||||
os.rename(file, f"{path}/{new_filename}")
|
os.rename(file, f"{path}/{new_filename}")
|
||||||
if (fileExtension.upper() in (cfg.fileext)):
|
if (fileExtension.upper() in (cfg.fileext)):
|
||||||
with open(file, 'r', encoding='utf-8', errors='ignore') as csvfile:
|
with open(f"{path}/{new_filename}", 'r', encoding='utf-8', errors='ignore') as csvfile:
|
||||||
lines = csvfile.readlines()
|
lines = csvfile.readlines()
|
||||||
|
|
||||||
unit_name = extract_value(cfg.units_name, filename, str(lines[0:10]))
|
unit_name = extract_value(cfg.units_name, filename, str(lines[0:10]))
|
||||||
|
|||||||
@@ -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