circular import issue
This commit is contained in:
1 parent
c66195d4cd
commit
d935ebe8fb
3 files changed
+27
-29
No files matched your search
@@ -4,50 +4,28 @@ Requires GOOGLE_APPLICATION_CREDENTIALS env var pointing to a service-account JS
|
|||||||
|
|
||||||
Usage from main.py:
|
Usage from main.py:
|
||||||
await bot.load_extension("firebase_website")
|
await bot.load_extension("firebase_website")
|
||||||
|
|
||||||
Provides:
|
|
||||||
get_db() → google.cloud.firestore.AsyncClient (shared, lazy-init)
|
|
||||||
"""
|
"""
|
||||||
######################################################################
|
######################################################################
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from google.cloud.firestore import AsyncClient
|
|
||||||
|
|
||||||
|
from .config import get_db # noqa: re‑export for other modules
|
||||||
from .sysinfo_sync import SysInfoSync
|
from .sysinfo_sync import SysInfoSync
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
_db: AsyncClient | None = None
|
|
||||||
_sync: SysInfoSync | None = None
|
_sync: SysInfoSync | None = None
|
||||||
|
|
||||||
|
|
||||||
def get_db() -> AsyncClient:
|
|
||||||
"""Return the shared Async Firestore client, creating it on first call."""
|
|
||||||
global _db
|
|
||||||
if _db is None:
|
|
||||||
creds_path = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
|
||||||
if creds_path is None:
|
|
||||||
raise RuntimeError(
|
|
||||||
"GOOGLE_APPLICATION_CREDENTIALS environment variable is not set. "
|
|
||||||
"Point it to your service-account JSON file."
|
|
||||||
)
|
|
||||||
_db = AsyncClient()
|
|
||||||
log.info("Firestore Admin SDK initialised (project %s)", _db.project)
|
|
||||||
return _db
|
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot: commands.Bot) -> None:
|
async def setup(bot: commands.Bot) -> None:
|
||||||
"""Start the sysinfo sync loop."""
|
|
||||||
global _sync
|
global _sync
|
||||||
get_db() # early init — fails fast if credentials are missing
|
get_db() # fail fast if credentials are missing
|
||||||
_sync = SysInfoSync()
|
_sync = SysInfoSync()
|
||||||
_sync.start()
|
_sync.start()
|
||||||
|
|
||||||
|
|
||||||
async def teardown(bot: commands.Bot) -> None:
|
async def teardown(bot: commands.Bot) -> None:
|
||||||
"""Stop the sysinfo sync loop."""
|
|
||||||
global _sync
|
global _sync
|
||||||
if _sync is not None:
|
if _sync is not None:
|
||||||
_sync.stop()
|
_sync.stop()
|
||||||
@@ -1,7 +1,28 @@
|
|||||||
"""Firebase project config — shared by all website integrations."""
|
"""Firebase project config + shared Admin SDK client."""
|
||||||
######################################################################
|
######################################################################
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from google.cloud.firestore import AsyncClient
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
PROJECT_ID = "esef-514bf"
|
PROJECT_ID = "esef-514bf"
|
||||||
|
SYSINFO_INTERVAL = 10 # seconds between pushes
|
||||||
|
|
||||||
# How often system stats are pushed (seconds)
|
_db: AsyncClient | None = None
|
||||||
SYSINFO_INTERVAL = 10
|
|
||||||
|
|
||||||
|
def get_db() -> AsyncClient:
|
||||||
|
"""Return the shared Firestore AsyncClient, creating it on first call."""
|
||||||
|
global _db
|
||||||
|
if _db is None:
|
||||||
|
creds_path = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||||
|
if creds_path is None:
|
||||||
|
raise RuntimeError(
|
||||||
|
"GOOGLE_APPLICATION_CREDENTIALS is not set. "
|
||||||
|
"Point it to your service-account JSON file."
|
||||||
|
)
|
||||||
|
_db = AsyncClient()
|
||||||
|
log.info("Firestore Admin SDK initialised (project %s)", _db.project)
|
||||||
|
return _db
|
||||||
@@ -7,8 +7,7 @@ import time
|
|||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
from . import get_db
|
from .config import get_db, SYSINFO_INTERVAL
|
||||||
from .config import SYSINFO_INTERVAL
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user