fix(reinstall): use OSTemplate.vmid (not template_vmid) and convert memory bytes->MB
- AttributeError: OSTemplate has no 'template_vmid' field; the actual column is 'vmid'. - Use OSTemplate.get_vmid_for_node() to support cross-node replicated templates, falling back to source_node/vmid otherwise. - VMInstance.memory is stored in bytes, but Proxmox config expects MB.
This commit is contained in:
@@ -126,12 +126,29 @@ class ConnectionManager:
|
||||
ws_manager = ConnectionManager()
|
||||
|
||||
|
||||
# Stores the main asyncio event loop set at application startup.
|
||||
# Background threads (APScheduler) use this to schedule coroutines safely.
|
||||
_main_loop: asyncio.AbstractEventLoop | None = None
|
||||
|
||||
|
||||
def set_main_loop(loop: asyncio.AbstractEventLoop) -> None:
|
||||
"""Call this once at application startup to register the running event loop."""
|
||||
global _main_loop
|
||||
_main_loop = loop
|
||||
|
||||
|
||||
def run_async_safe(coro) -> None:
|
||||
"""
|
||||
Schedule an async coroutine from a synchronous background thread.
|
||||
Used by APScheduler jobs to push WS updates without blocking.
|
||||
"""
|
||||
global _main_loop
|
||||
try:
|
||||
# Prefer the stored main loop (set at startup) for cross-thread scheduling
|
||||
if _main_loop is not None and _main_loop.is_running():
|
||||
asyncio.run_coroutine_threadsafe(coro, _main_loop)
|
||||
return
|
||||
# Fallback: try to get/run the current thread's loop
|
||||
loop = asyncio.get_event_loop()
|
||||
if loop.is_running():
|
||||
asyncio.run_coroutine_threadsafe(coro, loop)
|
||||
|
||||
Reference in New Issue
Block a user