Add PostgreSQL production backend to eliminate SQLite lock contention.
Support DATABASE_URL with connection pooling, pg_dump backups, SQLite migration script, and deploy_postgres.sh with docs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+14
-5
@@ -12,12 +12,15 @@ import threading
|
||||
import time
|
||||
from typing import Callable
|
||||
|
||||
from ctp_premarket_connect import should_auto_connect_now
|
||||
from ctp_premarket_connect import premarket_minutes_before, should_auto_connect_now
|
||||
from market_sessions import in_premarket_connect_window, is_trading_session
|
||||
from vnpy_bridge import ctp_try_auto_reconnect
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
RECONNECT_INTERVAL_SEC = 60
|
||||
TRADING_RECONNECT_INTERVAL_SEC = 15
|
||||
PREMARKET_RECONNECT_INTERVAL_SEC = 30
|
||||
|
||||
|
||||
def _auto_reconnect_enabled() -> bool:
|
||||
@@ -34,17 +37,23 @@ def start_ctp_reconnect_worker(
|
||||
get_setting_fn: Callable[[str, str], str] | None = None,
|
||||
interval: int = RECONNECT_INTERVAL_SEC,
|
||||
) -> None:
|
||||
"""定时检测 CTP 连接;仅在交易时段或盘前窗口内尝试重连,避免非交易时段反复登录。"""
|
||||
"""交易时段 / 盘前窗口内检测 CTP;断线则后台自动重连。"""
|
||||
|
||||
def _loop() -> None:
|
||||
while True:
|
||||
sleep_sec = max(5, interval)
|
||||
try:
|
||||
if _auto_reconnect_enabled() and should_auto_connect_now():
|
||||
mode = get_mode_fn()
|
||||
if ctp_try_auto_reconnect(mode):
|
||||
logger.debug("CTP 连接正常 [%s]", mode)
|
||||
ctp_try_auto_reconnect(mode)
|
||||
if is_trading_session():
|
||||
sleep_sec = TRADING_RECONNECT_INTERVAL_SEC
|
||||
elif in_premarket_connect_window(
|
||||
minutes_before=premarket_minutes_before(),
|
||||
):
|
||||
sleep_sec = PREMARKET_RECONNECT_INTERVAL_SEC
|
||||
except Exception as exc:
|
||||
logger.warning("CTP reconnect worker: %s", exc)
|
||||
time.sleep(max(5, interval))
|
||||
time.sleep(sleep_sec)
|
||||
|
||||
threading.Thread(target=_loop, daemon=True, name="ctp-reconnect-worker").start()
|
||||
|
||||
Reference in New Issue
Block a user