fix(mavvrik): reschedule background job after update_settings

PUT /mavvrik/settings saved new credentials to DB but the running
Orchestrator kept its old Client with stale api_endpoint/connection_id —
directly contradicting "update credentials without restarting".

Fix: after saving merged credentials, reschedule the job with a new
Client/Uploader/Orchestrator built from the merged values using
replace_existing=True — same pattern as initialize(). The updated
credentials take effect on the next scheduler tick.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Praveen Ghuge 2026-04-26 21:43:43 +05:30
parent cff49b8a01
commit 2f6742a700

View file

@ -221,6 +221,37 @@ class Service:
)
await self._settings.save(**merged)
# Reschedule the background job with the new credentials so the
# running Orchestrator uses the merged values immediately —
# without this, the in-memory Client keeps old credentials until restart.
from litellm.constants import (
MAVVRIK_EXPORT_INTERVAL_MINUTES,
MAVVRIK_EXPORT_USAGE_DATA_JOB_NAME,
)
import litellm.proxy.proxy_server as _pserver
_scheduler = getattr(_pserver, "scheduler", None)
if _scheduler is not None:
client = Client(
api_key=merged["api_key"],
api_endpoint=merged["api_endpoint"],
connection_id=merged["connection_id"],
)
uploader = Uploader(client=client)
orchestrator = Orchestrator(client=client, uploader=uploader)
_scheduler.add_job(
orchestrator.run,
"interval",
minutes=MAVVRIK_EXPORT_INTERVAL_MINUTES,
id=MAVVRIK_EXPORT_USAGE_DATA_JOB_NAME,
replace_existing=True,
)
verbose_proxy_logger.info(
"mavvrik: background job rescheduled with updated credentials"
)
return {"message": "Mavvrik settings updated successfully", "status": "success"}
# ------------------------------------------------------------------