MinaNasser commited on
Commit
4bafff4
·
1 Parent(s): 27b7895
Files changed (2) hide show
  1. .env +1 -1
  2. celery_app.py +24 -11
.env CHANGED
@@ -17,7 +17,7 @@ QDRANT_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJtIn0.NRbT0QP
17
 
18
 
19
  # ---------- REDIS ----------
20
- REDIS_HOST="https://steady-clam-77697.upstash.io"
21
  REDIS_PORT=6379
22
  REDIS_PASSWORD="gQAAAAAAAS-BAAIncDFiM2E3OGQ1MmU5Zjk0OGM5ODU2ZmMzYzc4NjZjYzdjMHAxNzc2OTc"
23
 
 
17
 
18
 
19
  # ---------- REDIS ----------
20
+ REDIS_HOST="steady-clam-77697.upstash.io"
21
  REDIS_PORT=6379
22
  REDIS_PASSWORD="gQAAAAAAAS-BAAIncDFiM2E3OGQ1MmU5Zjk0OGM5ODU2ZmMzYzc4NjZjYzdjMHAxNzc2OTc"
23
 
celery_app.py CHANGED
@@ -1,24 +1,37 @@
1
  # celery_app.py
2
  from celery import Celery
3
  import redis
 
4
  from config import get_settings
5
 
6
  settings = get_settings()
7
 
8
- # Upstash sometimes shows the endpoint as "host:port" in their console.
9
- # Split here so users can paste either format into the REDIS_HOST secret.
10
- _raw_host = settings.REDIS_HOST
11
- if ":" in _raw_host:
12
- REDIS_HOST, _port_str = _raw_host.rsplit(":", 1)
13
- REDIS_PORT = int(_port_str)
14
- else:
15
- REDIS_HOST = _raw_host
16
- REDIS_PORT = settings.REDIS_PORT
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
 
18
  REDIS_PASSWORD = settings.REDIS_PASSWORD
19
 
20
- # Upstash (and most managed Redis) uses rediss:// (TLS)
21
- # Local/Docker Redis uses redis:// (plain)
22
  if REDIS_PASSWORD:
23
  BROKER_URL = f"rediss://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/0?ssl_cert_reqs=CERT_NONE"
24
  BACKEND_URL = f"rediss://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/1?ssl_cert_reqs=CERT_NONE"
 
1
  # celery_app.py
2
  from celery import Celery
3
  import redis
4
+ from urllib.parse import urlparse
5
  from config import get_settings
6
 
7
  settings = get_settings()
8
 
9
+ def parse_redis_host(raw: str, default_port: int) -> tuple[str, int]:
10
+ """
11
+ Accept any of these formats for REDIS_HOST:
12
+ - "my-host.upstash.io"
13
+ - "my-host.upstash.io:6379"
14
+ - "https://my-host.upstash.io"
15
+ - "rediss://my-host.upstash.io:6379"
16
+ Always returns (hostname, port).
17
+ """
18
+ raw = raw.strip()
19
+ # If there's a scheme, use urlparse
20
+ if "://" in raw:
21
+ parsed = urlparse(raw)
22
+ host = parsed.hostname or raw
23
+ port = parsed.port or default_port
24
+ elif ":" in raw:
25
+ host, port_str = raw.rsplit(":", 1)
26
+ port = int(port_str)
27
+ else:
28
+ host = raw
29
+ port = default_port
30
+ return host, port
31
 
32
+ REDIS_HOST, REDIS_PORT = parse_redis_host(settings.REDIS_HOST, settings.REDIS_PORT)
33
  REDIS_PASSWORD = settings.REDIS_PASSWORD
34
 
 
 
35
  if REDIS_PASSWORD:
36
  BROKER_URL = f"rediss://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/0?ssl_cert_reqs=CERT_NONE"
37
  BACKEND_URL = f"rediss://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/1?ssl_cert_reqs=CERT_NONE"