Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lyon committed Jun 9, 2024
2 parents 2574276 + 7686974 commit 4abd612
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
22 changes: 13 additions & 9 deletions finalize_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,23 @@ def send_sentry(message):
else:
main_proc = subprocess.Popen(command, cwd=directory)
pid = main_proc.pid
time.sleep(5)
except Exception as e:
send_sentry(f"Failed to start backend\n{e}\nCommand: {command}")
raise e

try:
r = client.get(f"http://127.0.0.1:8000/get_main_pid/{pid}")
if r.status_code != 200:
send_sentry(f"Failed to start backend\n{r.text}")
raise Exception(f"Failed to start backend: {r.text}")
except Exception as e:
send_sentry(f"Failed to start backend\n{e}")
raise e
delayed = 0
r = None
while delayed < 30:
try:
time.sleep(1)
delayed += 1
r = client.get(f"http://127.0.0.1:8000/get_main_pid/{pid}", timeout=1)
except Exception as e:
pass
if r is None:
send_sentry(f"Failed to start backend\nTimeout after {delayed} seconds")
raise Exception("nTimeout after {delayed} seconds")

try:
client.get("http://127.0.0.1:8000/backend/shutdown")
except:
Expand Down
30 changes: 22 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ def get_plugin_info(plugin_name: str):
def get_plugin_config(plugin_name: str):
if plugin_name in plugin_list:
sleep = 0
while plugin_states[plugin_name] != "RUNNING":
start_plugin(plugin_name)
time.sleep(5)
sleep += 5
if sleep > 120:
return {"status": "failed", "error": "Plugin too slow to start"}
# while plugin_states[plugin_name] != "RUNNING":
# start_plugin(plugin_name)
# time.sleep(5)
# sleep += 5
# if sleep > 120:
# return {"status": "failed", "error": "Plugin too slow to start"}
if plugin_name in port_mapping.keys():
port = port_mapping[plugin_name]
r = client.get("http://127.0.0.1:" + port + "/get_config")
Expand All @@ -305,7 +305,16 @@ def get_plugin_config(plugin_name: str):
else:
return {"status": "failed", "error": r.text}
else:
raise HTTPException(status_code=404, detail="Plugin must be running to check config")
try:
print(f"Getting config for {plugin_name}")
print(f"plugin_config.{plugin_name}")
data = retrieve_data(f"plugin_config.{plugin_name}")
print(data)
return data
except Exception as e:
print(e)
print("Plugin config not found in DB, getting default")
return get_plugin_info(plugin_name)["config"]
else:
raise HTTPException(status_code=404, detail="Plugin not found")

Expand All @@ -325,7 +334,12 @@ def set_plugin_config(plugin_name: str, config: dict):
# store_data(f"{plugin_name}_model_memory", {"memory": int(new_model_memory)})
return {"job_id": job.id}
else:
raise HTTPException(status_code=404, detail="Plugin must be running to change config")
try:
original_config = retrieve_data(f"plugin_config.{self.plugin_name}")
except:
original_config = get_plugin_info(plugin_name)["config"]
original_config.update(config)
store_data(f"plugin_config.{plugin_name}", original_config)
else:
raise HTTPException(status_code=404, detail="Plugin not found")

Expand Down

0 comments on commit 4abd612

Please sign in to comment.