Skip to content

Commit 6642c26

Browse files
committed
moved remaining db config into main bot
1 parent f83a35f commit 6642c26

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/discord-cluster-manager/bot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from discord import app_commands
1616
from discord.ext import commands
1717
from env import (
18+
DATABASE_URL,
19+
DISABLE_SSL,
1820
DISCORD_CLUSTER_STAGING_ID,
1921
DISCORD_DEBUG_CLUSTER_STAGING_ID,
2022
DISCORD_DEBUG_TOKEN,
@@ -62,6 +64,8 @@ def __init__(self, debug_mode=False):
6264
POSTGRES_USER,
6365
POSTGRES_PASSWORD,
6466
POSTGRES_PORT,
67+
url=DATABASE_URL,
68+
ssl_mode="require" if not DISABLE_SSL else "disable",
6569
)
6670

6771
try:

src/discord-cluster-manager/leaderboard_db.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
from typing import List, Optional
66

77
import psycopg2
8-
from env import (
9-
DATABASE_URL,
10-
DISABLE_SSL,
11-
)
128
from run_eval import CompileResult, RunResult, SystemInfo
139
from task import LeaderboardTask
1410
from utils import (
@@ -25,7 +21,9 @@
2521

2622

2723
class LeaderboardDB:
28-
def __init__(self, host: str, database: str, user: str, password: str, port: str = "5432"):
24+
def __init__(
25+
self, host: str, database: str, user: str, password: str, port: str, url: str, ssl_mode: str
26+
):
2927
"""Initialize database connection parameters"""
3028
self.connection_params = {
3129
"host": host,
@@ -34,6 +32,8 @@ def __init__(self, host: str, database: str, user: str, password: str, port: str
3432
"password": password,
3533
"port": port,
3634
}
35+
self.url = url
36+
self.ssl_mode = ssl_mode
3737
self.connection: Optional[psycopg2.extensions.connection] = None
3838
self.refcount: int = 0
3939
self.cursor: Optional[psycopg2.extensions.cursor] = None
@@ -43,8 +43,8 @@ def connect(self) -> bool:
4343
"""Establish connection to the database"""
4444
try:
4545
self.connection = (
46-
psycopg2.connect(DATABASE_URL, sslmode="require" if not DISABLE_SSL else "disable")
47-
if DATABASE_URL
46+
psycopg2.connect(self.url, sslmode=self.ssl_mode)
47+
if self.url
4848
else psycopg2.connect(**self.connection_params)
4949
)
5050
self.cursor = self.connection.cursor()

0 commit comments

Comments
 (0)