Skip to content

Commit 84422ac

Browse files
Pigbibiclaude
andauthored
feat(config): auto-sync plugin mount strategy field on startup (#246)
* feat(env): add .env.example template with all required env vars Lists all environment variables needed for LongBridge platform operation. Co-Authored-By: Claude <noreply@anthropic.com> * feat(config): auto-sync plugin mount strategy field on startup Plugin mounts with outdated strategy names are auto-corrected to match RUNTIME_TARGET_JSON.strategy_profile at module load time. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent b6550aa commit 84422ac

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,37 @@ def get_project_id():
7474
ACCOUNT_PREFIX = RUNTIME_SETTINGS.account_prefix
7575
STRATEGY_PROFILE = RUNTIME_SETTINGS.strategy_profile
7676
STRATEGY_DISPLAY_NAME = RUNTIME_SETTINGS.strategy_display_name
77+
78+
79+
def _normalize_plugin_mounts_strategy(raw_mounts_json: str | None) -> str | None:
80+
if not raw_mounts_json:
81+
return raw_mounts_json
82+
try:
83+
mounts = json.loads(raw_mounts_json)
84+
except json.JSONDecodeError:
85+
return raw_mounts_json
86+
if not isinstance(mounts, dict):
87+
return raw_mounts_json
88+
plugins = mounts.get("strategy_plugins")
89+
if not isinstance(plugins, list):
90+
return raw_mounts_json
91+
changed = False
92+
for entry in plugins:
93+
if not isinstance(entry, dict):
94+
continue
95+
old = entry.get("strategy")
96+
if old and old != STRATEGY_PROFILE:
97+
entry["strategy"] = STRATEGY_PROFILE
98+
changed = True
99+
print(f"[config-sync] Plugin mount strategy corrected: {old}{STRATEGY_PROFILE}", flush=True)
100+
return json.dumps(mounts, ensure_ascii=False) if changed else raw_mounts_json
101+
102+
103+
if hasattr(RUNTIME_SETTINGS, "strategy_plugin_mounts_json"):
104+
normalized = _normalize_plugin_mounts_strategy(RUNTIME_SETTINGS.strategy_plugin_mounts_json)
105+
if normalized != RUNTIME_SETTINGS.strategy_plugin_mounts_json:
106+
object.__setattr__(RUNTIME_SETTINGS, "strategy_plugin_mounts_json", normalized)
107+
77108
ACCOUNT_REGION = RUNTIME_SETTINGS.account_region
78109
MARKET = RUNTIME_SETTINGS.market
79110
MARKET_CALENDAR = RUNTIME_SETTINGS.market_calendar

0 commit comments

Comments
 (0)