Skip to content

Commit 103aba8

Browse files
committed
feat: Improves task manager
1 parent cf8d8f1 commit 103aba8

File tree

5 files changed

+10
-41
lines changed

5 files changed

+10
-41
lines changed

app/modules/flamapy/services.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
from flamapy.metamodels.fm_metamodel.operations import FMMetrics
1111
from flamapy.metamodels.pysat_metamodel.operations import PySATMetrics # noqa
1212
from flamapy.metamodels.pysat_metamodel.transformations import FmToPysat # noqa
13-
from core.managers.task_queue_manager import TaskQueueManager
1413
from uvl.UVLCustomLexer import UVLCustomLexer
1514
from uvl.UVLPythonParser import UVLPythonParser
1615

1716
from app.modules.flamapy.repositories import FlamapyRepository
17+
from core.managers.task_queue_manager import TaskQueueManager
1818
from core.services.BaseService import BaseService
1919

2020
logger = logging.getLogger(__name__)
@@ -38,11 +38,7 @@ def get_analysis_results(self, fm_model: FeatureModel) -> list[dict[str, Any]]:
3838
return fm_results
3939

4040
def check_uvl_async(self, filepath: str):
41-
task = TaskQueueManager().enqueue_task(
42-
"app.modules.flamapy.tasks.check_uvl",
43-
filepath=filepath,
44-
timeout=5
45-
)
41+
task = TaskQueueManager().enqueue_task("app.modules.flamapy.tasks.check_uvl", filepath=filepath, timeout=5)
4642
return {"task_id": task.id}
4743

4844
def check_uvl(self, filepath: str):

app/modules/flamapy/tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from app.modules.flamapy.services import FlamapyService
22

3+
34
def check_uvl(filepath: str):
45
service = FlamapyService()
56
return service.check_uvl(filepath)

app/modules/hubfile/routes.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,6 @@ def upload_file():
7272
ext = file.filename.lower().split(".")[-1]
7373
current_app.logger.info(f"📦 Detected extension: {ext}")
7474

75-
if ext == "uvl":
76-
try:
77-
current_app.logger.info("⚙️ Encolando validación UVL async...")
78-
task_info = flamapy_service.check_uvl_async(temp_file_path)
79-
current_app.logger.info(f"✅ Tarea encolada correctamente: {task_info}")
80-
return (
81-
jsonify(
82-
{
83-
"message": f"{ext.upper()} uploaded successfully (validation running in background)",
84-
"filename": unique_filename,
85-
"task_id": task_info["task_id"],
86-
}
87-
),
88-
202,
89-
)
90-
except Exception as e:
91-
current_app.logger.exception("❌ Error encolando validación UVL")
92-
if os.path.exists(temp_file_path):
93-
os.remove(temp_file_path)
94-
current_app.logger.info(f"🗑️ Archivo temporal eliminado tras fallo: {temp_file_path}")
95-
return jsonify({"message": f"Error encolando validación UVL: {str(e)}"}), 500
96-
97-
elif ext == "zip":
98-
current_app.logger.info("📦 ZIP detectado → no se valida, solo se acepta")
99-
# Do not validate ZIPs, just accept them
100-
pass
101-
else:
102-
current_app.logger.warning(f"⚠️ Extensión no soportada: {ext}")
103-
os.remove(temp_file_path)
104-
current_app.logger.info(f"🗑️ Archivo eliminado: {temp_file_path}")
105-
return jsonify({"message": "Unsupported file type"}), 400
106-
10775
current_app.logger.info(f"✅ Archivo {unique_filename} aceptado con extensión {ext}")
10876
return (
10977
jsonify(

app/modules/zenodo/services.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,12 @@ def upload_zip(self, dataset: DataSet, deposition_id: int, zip_path: str) -> dic
251251
response = requests.post(upload_url, params=self.params, data=data, files=files)
252252

253253
if response.status_code != 201:
254-
logger.error(f"Failed to upload ZIP: {response.content}")
255-
raise Exception(f"Error uploading ZIP to Zenodo: {response.json()}")
254+
logger.error(f"Failed to upload ZIP: {response.status_code} {response.reason}")
255+
try:
256+
error_payload = response.json() # Zenodo a veces sí devuelve JSON de error
257+
except ValueError:
258+
error_payload = response.text # pero si no, mostramos el HTML/texto plano
259+
raise Exception(f"Error uploading ZIP to Zenodo: {error_payload}")
256260

257261
return response.json()
258262

core/managers/task_queue_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ def enqueue_task(self, task_name: str, *args, timeout=None, **kwargs):
4747
job = self.queue.enqueue(task_name, *args, **kwargs, job_timeout=timeout)
4848
logger.info(f"Task '{task_name}' enqueued with id={job.id}, args={args}, kwargs={kwargs}, timeout={timeout}")
4949

50-
return job
50+
return job

0 commit comments

Comments
 (0)