Skip to content

Commit

Permalink
Enriching failure message from task_schedule_css_selector_generation …
Browse files Browse the repository at this point in the history
…with info about elements that task should've processed
  • Loading branch information
ivnglkv committed Apr 21, 2024
1 parent e06aec9 commit 600d62e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/css_locators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
__all__ = [
"task_schedule_css_locator_generation",
"CSS_SELECTOR_GEN_TASK_PREFIX",
"task_schedule_css_selector_generation",
"inject_css_selector_generator_scripts",
]

from .tasks import task_schedule_css_selector_generation
from .tasks import task_schedule_css_selector_generation, CSS_SELECTOR_GEN_TASK_PREFIX
from .utils import inject_css_selector_generator_scripts
3 changes: 3 additions & 0 deletions app/css_locators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
logger = logging.getLogger(__name__)


CSS_SELECTOR_GEN_TASK_PREFIX = "css-selectors-gen-"


@celery_app.task(bind=True)
def task_schedule_css_selector_generation(
self, document_path: str, elements_ids: List[str]
Expand Down
12 changes: 10 additions & 2 deletions utils/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import app.mongodb as mongodb
from app.celery_app import celery_app
from app.constants import CeleryStatuses, WebSocketResponseActions
from app.css_locators import inject_css_selector_generator_scripts
from app.css_locators import inject_css_selector_generator_scripts, CSS_SELECTOR_GEN_TASK_PREFIX
from app.logger import logger
from app.models import LoggingInfoModel, TaskStatusModel, XPathGenerationModel, CSSSelectorGenerationModel
from app.redis_app import redis_app
Expand Down Expand Up @@ -70,6 +70,14 @@ async def wait_until_task_reach_status(
task_dict = task.model_dump()
# deleting underscores in task_id if any to send to frontend
task_dict["id"] = task_dict["id"].strip("_")

# Informing frontend about failed elements from
# task_schedule_css_locator_generation task, because otherwise
# this info will be lost. In schedule_multiple_xpath_generations task
# the id of an element is the task id, so it doesn't need this logic
if task_id.startswith(CSS_SELECTOR_GEN_TASK_PREFIX):
task_dict["elements_ids"] = task_result_obj.kwargs.get("elements_ids")

error_message = str(task_result_obj.result)
response = get_websocket_response(
action=WebSocketResponseActions.STATUS_CHANGED,
Expand Down Expand Up @@ -344,7 +352,7 @@ async def process_incoming_ws_request(

for start_idx, end_idx in jobs_chunks:
task_id = convert_task_id_if_exists(
f"css-selectors-gen-{uuid.uuid4()}"
f"{CSS_SELECTOR_GEN_TASK_PREFIX}{uuid.uuid4()}"
)
task_kwargs = {
"document_path": str(html_file),
Expand Down

0 comments on commit 600d62e

Please sign in to comment.