Skip to content

Commit 625914e

Browse files
committed
Avoid web app loading model
1 parent 18852d0 commit 625914e

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

src/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pydantic import ValidationError
77

88
from src.config import load_config
9-
from src.tasks import build_classify_and_update_chain
9+
from src.queueing import build_classify_and_update_chain
1010
from src.turn_webhook import TurnWebhook
1111
from src.utils import validate_turn_signature
1212

src/queueing.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Celery task submission helpers for producer processes."""
2+
3+
from celery import chain
4+
5+
from src.celery_app import celery_app
6+
7+
CLASSIFY_TURN_MESSAGE_TASK = "src.tasks.classify_turn_message"
8+
UPDATE_TURN_MESSAGE_LABEL_TASK = "src.tasks.update_turn_message_label"
9+
10+
11+
def build_classify_and_update_chain(message_id: str, message_text: str):
12+
"""Build a Celery chain without importing worker-only task modules."""
13+
return chain(
14+
celery_app.signature(
15+
CLASSIFY_TURN_MESSAGE_TASK,
16+
args=(message_id, message_text),
17+
),
18+
celery_app.signature(UPDATE_TURN_MESSAGE_LABEL_TASK),
19+
)

src/tasks.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
"""Celery tasks for async processing."""
1+
"""Celery task implementations for worker processes."""
22

33
import logging
44
from pathlib import Path
55

6-
from celery import chain
7-
86
from src.celery_app import celery_app
97
from src.intent_classifier import IntentClassifier
108
from src.turn_client import TurnAPIClient, TurnAPIServerError
@@ -140,11 +138,3 @@ def update_turn_message_label(classification: dict) -> dict:
140138
exc_info=True,
141139
)
142140
raise
143-
144-
145-
def build_classify_and_update_chain(message_id: str, message_text: str):
146-
"""Build a Celery chain that classifies then updates the Turn label."""
147-
return chain(
148-
classify_turn_message.s(message_id, message_text),
149-
update_turn_message_label.s(),
150-
)

tests/test_tasks.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
import pytest
44

55
from src.celery_app import celery_app
6-
from src.tasks import (
7-
build_classify_and_update_chain,
8-
classify_turn_message,
9-
update_turn_message_label,
10-
)
6+
from src.queueing import build_classify_and_update_chain
7+
from src.tasks import classify_turn_message, update_turn_message_label
118
from src.turn_client import TurnAPIClientError, TurnAPIServerError
129

1310
# Enable eager mode for all tests in this module (run tasks synchronously)

0 commit comments

Comments
 (0)