fix: VPS fresh-DB bootstrap — sync OPENAI_API_KEY from env to DB at startup + show countdown before first cycle
- main.py startup: if DB has no openai_api_key but OPENAI_API_KEY env var is set, auto-save it so cycle trigger returns 200 instead of 400 - Config.tsx: move NextRunCountdown outside cs?.last_cycle block so it renders even when no cycle has run yet Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,15 +22,25 @@ app.add_middleware(
|
||||
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
import logging
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
init_db()
|
||||
|
||||
# Clean up cycles that were left in 'running' state by a previous crashed process
|
||||
stale = cleanup_stale_running_cycles()
|
||||
if stale:
|
||||
import logging
|
||||
logging.getLogger(__name__).warning(
|
||||
f"[Startup] Cleaned up {stale} stale 'running' cycle(s) — server likely reloaded mid-cycle"
|
||||
)
|
||||
_log.warning(f"[Startup] Cleaned up {stale} stale 'running' cycle(s) — server likely reloaded mid-cycle")
|
||||
|
||||
# Sync OpenAI key: env var → DB (useful on fresh VPS deployments)
|
||||
key = get_config("openai_api_key") or ""
|
||||
if not key:
|
||||
env_key = os.environ.get("OPENAI_API_KEY", "")
|
||||
if env_key:
|
||||
from services.database import save_config
|
||||
save_config("openai_api_key", env_key)
|
||||
key = env_key
|
||||
_log.info("[Startup] OPENAI_API_KEY synced from environment to DB config")
|
||||
if key:
|
||||
os.environ["OPENAI_API_KEY"] = key
|
||||
# Seed built-in patterns into DB (idempotent)
|
||||
|
||||
Reference in New Issue
Block a user