ColettoG commited on
Commit
ca01bc4
·
1 Parent(s): dfe2edc

fix dockerfile and config

Browse files
Dockerfile CHANGED
@@ -26,7 +26,7 @@ COPY src /app/src
26
  RUN useradd -m -u 10001 appuser && chown -R appuser:appuser /app
27
  USER appuser
28
 
29
- EXPOSE 8000
30
 
31
  # GEMINI_API_KEY must be provided at runtime
32
- CMD ["sh", "-c", "uvicorn src.app:app --host 0.0.0.0 --port ${PORT}"]
 
26
  RUN useradd -m -u 10001 appuser && chown -R appuser:appuser /app
27
  USER appuser
28
 
29
+ EXPOSE 7860
30
 
31
  # GEMINI_API_KEY must be provided at runtime
32
+ CMD ["sh", "-c", "uvicorn src.app:app --host 0.0.0.0 --port ${PORT:-7860}"]
src/agents/database/client.py CHANGED
@@ -1,16 +1,28 @@
 
1
  import clickhouse_connect
2
  from src.agents.database.config import Config
3
 
 
 
4
  _client = None
5
 
6
  def _create_client():
7
- return clickhouse_connect.get_client(
8
- host=Config.CLICKHOUSE_HOST,
9
- port=Config.CLICKHOUSE_PORT,
10
- username=Config.CLICKHOUSE_USER,
11
- password=Config.CLICKHOUSE_PASSWORD,
12
- database=Config.CLICKHOUSE_DATABASE
13
- )
 
 
 
 
 
 
 
 
 
14
 
15
  def get_client():
16
  global _client
@@ -19,18 +31,21 @@ def get_client():
19
  return _client
20
 
21
  def try_get_client():
22
- try:
23
- return get_client()
24
- except Exception:
25
- return None
26
 
27
  def is_database_available() -> bool:
28
  try:
29
  client = get_client()
30
- client.query("SELECT 1")
31
- return True
 
 
32
  except Exception:
33
  return False
34
 
35
  def execute_query(query: str):
36
- return get_client().query(query)
 
 
 
 
 
1
+ import logging
2
  import clickhouse_connect
3
  from src.agents.database.config import Config
4
 
5
+ logger = logging.getLogger(__name__)
6
+
7
  _client = None
8
 
9
  def _create_client():
10
+ if not Config.CLICKHOUSE_ENABLED:
11
+ logger.warning("ClickHouse is disabled via config.")
12
+ return None
13
+
14
+ try:
15
+ return clickhouse_connect.get_client(
16
+ host=Config.CLICKHOUSE_HOST,
17
+ port=Config.CLICKHOUSE_PORT,
18
+ username=Config.CLICKHOUSE_USER,
19
+ password=Config.CLICKHOUSE_PASSWORD,
20
+ database=Config.CLICKHOUSE_DATABASE,
21
+ connect_timeout=5,
22
+ )
23
+ except Exception as e:
24
+ logger.error(f"Failed to connect to ClickHouse: {e}")
25
+ return None
26
 
27
  def get_client():
28
  global _client
 
31
  return _client
32
 
33
  def try_get_client():
34
+ return get_client()
 
 
 
35
 
36
  def is_database_available() -> bool:
37
  try:
38
  client = get_client()
39
+ if client:
40
+ client.query("SELECT 1")
41
+ return True
42
+ return False
43
  except Exception:
44
  return False
45
 
46
  def execute_query(query: str):
47
+ client = get_client()
48
+ if client:
49
+ return client.query(query)
50
+ logger.warning("Attempted to execute query but ClickHouse client is not available.")
51
+ return None
src/agents/database/config.py CHANGED
@@ -1,14 +1,16 @@
1
  import os
2
 
3
  class Config:
4
- # Use clickhouse+http:// for HTTP interface or clickhouse+native:// for native interface
5
- CLICKHOUSE_URI = "clickhouse+http://default:@localhost:8123/default"
6
 
7
- CLICKHOUSE_HOST = 'localhost'
8
- CLICKHOUSE_PORT = 8123 # HTTP port
9
- CLICKHOUSE_USER = 'default'
10
- CLICKHOUSE_PASSWORD = ''
11
- CLICKHOUSE_DATABASE = 'default'
12
- # Alternative native connection (faster, recommended for production)
13
- # CLICKHOUSE_URI = "clickhouse+native://default:@localhost:9000/default"
 
 
14
  GLACIER_API_KEY = os.getenv("GLACIER_API_KEY")
 
1
  import os
2
 
3
  class Config:
4
+ # ClickHouse Configuration
5
+ CLICKHOUSE_ENABLED = os.getenv("CLICKHOUSE_ENABLED", "false").lower() == "true"
6
 
7
+ CLICKHOUSE_HOST = os.getenv("CLICKHOUSE_HOST", "localhost")
8
+ CLICKHOUSE_PORT = int(os.getenv("CLICKHOUSE_PORT", "8123"))
9
+ CLICKHOUSE_USER = os.getenv("CLICKHOUSE_USER", "default")
10
+ CLICKHOUSE_PASSWORD = os.getenv("CLICKHOUSE_PASSWORD", "")
11
+ CLICKHOUSE_DATABASE = os.getenv("CLICKHOUSE_DATABASE", "default")
12
+
13
+ # Construct URI for reference if needed
14
+ CLICKHOUSE_URI = f"clickhouse+http://{CLICKHOUSE_USER}:{CLICKHOUSE_PASSWORD}@{CLICKHOUSE_HOST}:{CLICKHOUSE_PORT}/{CLICKHOUSE_DATABASE}"
15
+
16
  GLACIER_API_KEY = os.getenv("GLACIER_API_KEY")