fix(celery): adjust try-catch logic to improve error handling

Capturing the instantiation of the database and dataset manager objects inside the try-catch will cause errors if something else fails.

If an exception occurs and the dataset_manager is not initialised, the code inside the catch block will fail.
This commit is contained in:
2026-03-04 21:18:59 +00:00
parent fcdac6f3bb
commit e20d0689e8

View File

@@ -2,17 +2,15 @@ import pandas as pd
from server.queue.celery_app import celery from server.queue.celery_app import celery
from server.analysis.enrichment import DatasetEnrichment from server.analysis.enrichment import DatasetEnrichment
@celery.task(bind=True, max_retries=3)
def process_dataset(self, dataset_id: int, posts: list, topics: dict):
try:
from server.db.database import PostgresConnector from server.db.database import PostgresConnector
from server.core.datasets import DatasetManager from server.core.datasets import DatasetManager
@celery.task(bind=True, max_retries=3)
def process_dataset(self, dataset_id: int, posts: list, topics: dict):
db = PostgresConnector() db = PostgresConnector()
dataset_manager = DatasetManager(db) dataset_manager = DatasetManager(db)
try:
df = pd.DataFrame(posts) df = pd.DataFrame(posts)
processor = DatasetEnrichment(df, topics) processor = DatasetEnrichment(df, topics)