add geoip
This commit is contained in:
25
app/service/init_geoip.py
Normal file
25
app/service/init_geoip.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
[GeoIP] Initialization Service
|
||||
Initialize the GeoIP database when the application starts
|
||||
"""
|
||||
import asyncio
|
||||
from app.dependencies.geoip import get_geoip_helper
|
||||
from app.log import logger
|
||||
|
||||
async def init_geoip():
|
||||
"""
|
||||
Asynchronously initialize the GeoIP database
|
||||
"""
|
||||
try:
|
||||
geoip = get_geoip_helper()
|
||||
logger.info("[GeoIP] Initializing GeoIP database...")
|
||||
|
||||
# Run the synchronous update method in a background thread
|
||||
loop = asyncio.get_event_loop()
|
||||
await loop.run_in_executor(None, geoip.update)
|
||||
|
||||
logger.info("[GeoIP] GeoIP database initialization completed")
|
||||
except Exception as e:
|
||||
logger.error(f"[GeoIP] GeoIP database initialization failed: {e}")
|
||||
# Do not raise an exception to avoid blocking application startup
|
||||
Reference in New Issue
Block a user