VietCat commited on
Commit
16ff3c7
·
1 Parent(s): 88ec76e

fix startup error

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. app/main.py +21 -3
Dockerfile CHANGED
@@ -7,4 +7,4 @@ RUN pip install --no-cache-dir -r requirements.txt
7
 
8
  COPY . .
9
 
10
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
 
7
 
8
  COPY . .
9
 
10
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app/main.py CHANGED
@@ -5,6 +5,7 @@ import json
5
  from typing import Dict, Any, List
6
  import asyncio
7
  from concurrent.futures import ThreadPoolExecutor
 
8
 
9
  from .config import Settings, get_settings
10
  from .facebook import FacebookClient
@@ -30,24 +31,40 @@ app.add_middleware(
30
  settings = get_settings()
31
  setup_logging(settings.log_level)
32
 
 
 
 
 
 
33
  facebook_client = FacebookClient(settings.facebook_app_secret)
 
34
  sheets_client = SheetsClient(
35
  settings.google_sheets_credentials_file,
36
  settings.google_sheets_token_file,
37
  settings.conversation_sheet_id
38
  )
 
39
  supabase_client = SupabaseClient(settings.supabase_url, settings.supabase_key)
 
40
  embedding_client = EmbeddingClient()
41
 
42
  # Keywords to look for in messages
43
  VEHICLE_KEYWORDS = ["xe máy", "ô tô", "xe đạp", "xe hơi"]
44
 
 
45
  app.include_router(health_router)
46
 
47
- ensure_log_dir()
48
  validate_config(settings)
 
49
  executor = ThreadPoolExecutor(max_workers=4)
50
 
 
 
 
 
 
 
51
  @app.get("/webhook")
52
  async def verify_webhook(request: Request):
53
  """
@@ -173,8 +190,9 @@ def format_search_results(matches: List[Dict[str, Any]]) -> str:
173
 
174
  if __name__ == "__main__":
175
  import uvicorn
 
176
  uvicorn.run(
177
  "app.main:app",
178
- host=settings.host,
179
- port=settings.port
180
  )
 
5
  from typing import Dict, Any, List
6
  import asyncio
7
  from concurrent.futures import ThreadPoolExecutor
8
+ import os
9
 
10
  from .config import Settings, get_settings
11
  from .facebook import FacebookClient
 
31
  settings = get_settings()
32
  setup_logging(settings.log_level)
33
 
34
+ logger.info("[STARTUP] Đang lấy PORT từ biến môi trường hoặc config...")
35
+ port = int(os.environ.get("PORT", settings.port if hasattr(settings, 'port') else 7860))
36
+ logger.info(f"[STARTUP] PORT sử dụng: {port}")
37
+
38
+ logger.info("[STARTUP] Khởi tạo FacebookClient...")
39
  facebook_client = FacebookClient(settings.facebook_app_secret)
40
+ logger.info("[STARTUP] Khởi tạo SheetsClient...")
41
  sheets_client = SheetsClient(
42
  settings.google_sheets_credentials_file,
43
  settings.google_sheets_token_file,
44
  settings.conversation_sheet_id
45
  )
46
+ logger.info("[STARTUP] Khởi tạo SupabaseClient...")
47
  supabase_client = SupabaseClient(settings.supabase_url, settings.supabase_key)
48
+ logger.info("[STARTUP] Khởi tạo EmbeddingClient...")
49
  embedding_client = EmbeddingClient()
50
 
51
  # Keywords to look for in messages
52
  VEHICLE_KEYWORDS = ["xe máy", "ô tô", "xe đạp", "xe hơi"]
53
 
54
+ logger.info("[STARTUP] Mount health router...")
55
  app.include_router(health_router)
56
 
57
+ logger.info("[STARTUP] Validate config...")
58
  validate_config(settings)
59
+
60
  executor = ThreadPoolExecutor(max_workers=4)
61
 
62
+ @app.get("/")
63
+ async def root():
64
+ """Endpoint root để kiểm tra trạng thái app."""
65
+ logger.info("[HEALTH] Truy cập endpoint root /")
66
+ return {"status": "ok"}
67
+
68
  @app.get("/webhook")
69
  async def verify_webhook(request: Request):
70
  """
 
190
 
191
  if __name__ == "__main__":
192
  import uvicorn
193
+ logger.info("[STARTUP] Bắt đầu chạy uvicorn server...")
194
  uvicorn.run(
195
  "app.main:app",
196
+ host="0.0.0.0",
197
+ port=port
198
  )