calebhan commited on
Commit
34a43d6
·
1 Parent(s): b8ea8ac

deployment 21

Browse files
Files changed (2) hide show
  1. backend/celery_app.py +9 -1
  2. start-backend.sh +22 -16
backend/celery_app.py CHANGED
@@ -1,6 +1,7 @@
1
  """Celery application configuration."""
2
  import sys
3
  from pathlib import Path
 
4
 
5
  # Ensure backend directory is in Python path for imports
6
  backend_dir = Path(__file__).parent.resolve()
@@ -13,13 +14,15 @@ from app_config import settings
13
 
14
  # Determine broker and backend based on configuration
15
  if settings.use_fake_redis:
16
- # Use in-memory broker for development/HF Spaces
17
  broker_url = "memory://"
18
  backend_url = "cache+memory://"
 
19
  else:
20
  # Use Redis for production
21
  broker_url = settings.redis_url
22
  backend_url = settings.redis_url
 
23
 
24
  # Initialize Celery
25
  celery_app = Celery(
@@ -35,6 +38,11 @@ celery_app.conf.update(
35
  result_serializer="json",
36
  timezone="UTC",
37
  enable_utc=True,
 
 
 
 
 
38
 
39
  # Task settings
40
  task_track_started=True,
 
1
  """Celery application configuration."""
2
  import sys
3
  from pathlib import Path
4
+ import os
5
 
6
  # Ensure backend directory is in Python path for imports
7
  backend_dir = Path(__file__).parent.resolve()
 
14
 
15
  # Determine broker and backend based on configuration
16
  if settings.use_fake_redis:
17
+ # Use eager mode for HF Spaces - execute tasks synchronously
18
  broker_url = "memory://"
19
  backend_url = "cache+memory://"
20
+ task_always_eager = True
21
  else:
22
  # Use Redis for production
23
  broker_url = settings.redis_url
24
  backend_url = settings.redis_url
25
+ task_always_eager = False
26
 
27
  # Initialize Celery
28
  celery_app = Celery(
 
38
  result_serializer="json",
39
  timezone="UTC",
40
  enable_utc=True,
41
+
42
+ # Eager mode for HF Spaces (synchronous execution)
43
+ task_always_eager=task_always_eager,
44
+ task_eager_propagates=True,
45
+ enable_utc=True,
46
 
47
  # Task settings
48
  task_track_started=True,
start-backend.sh CHANGED
@@ -1,22 +1,28 @@
1
  #!/bin/bash
2
  set -e
3
 
4
- echo "Starting Rescored backend..."
5
 
6
  cd /app/backend
7
 
8
- # Start Celery worker in the background
9
- echo "Starting Celery worker..."
10
- celery -A celery_app worker --loglevel=info --concurrency=1 &
11
- CELERY_PID=$!
12
-
13
- # Give Celery a moment to start
14
- sleep 2
15
-
16
- # Start FastAPI server in the foreground
17
- echo "Starting FastAPI server on port ${API_PORT}..."
18
- python -u main.py &
19
- API_PID=$!
20
-
21
- # Wait for both processes
22
- wait $CELERY_PID $API_PID
 
 
 
 
 
 
 
1
  #!/bin/bash
2
  set -e
3
 
4
+ echo "Starting Rescored backend..."
5
 
6
  cd /app/backend
7
 
8
+ # Check if using fake Redis (eager mode - no worker needed)
9
+ if [ "$USE_FAKE_REDIS" = "true" ]; then
10
+ echo "Using eager mode (synchronous task execution)"
11
+ exec python -u main.py
12
+ else
13
+ # Production mode - start Celery worker in background
14
+ echo "Starting Celery worker..."
15
+ celery -A celery_app worker --loglevel=info --concurrency=1 &
16
+ CELERY_PID=$!
17
+
18
+ # Give Celery a moment to start
19
+ sleep 2
20
+
21
+ # Start FastAPI server
22
+ echo "Starting FastAPI server on port ${API_PORT}..."
23
+ python -u main.py &
24
+ API_PID=$!
25
+
26
+ # Wait for both processes
27
+ wait $CELERY_PID $API_PID
28
+ fi