Skip to content

Commit 4abd612

Browse files
author
Bryan Lyon
committed
2 parents 2574276 + 7686974 commit 4abd612

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

finalize_install.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,23 @@ def send_sentry(message):
9494
else:
9595
main_proc = subprocess.Popen(command, cwd=directory)
9696
pid = main_proc.pid
97-
time.sleep(5)
9897
except Exception as e:
9998
send_sentry(f"Failed to start backend\n{e}\nCommand: {command}")
10099
raise e
101100

102-
try:
103-
r = client.get(f"http://127.0.0.1:8000/get_main_pid/{pid}")
104-
if r.status_code != 200:
105-
send_sentry(f"Failed to start backend\n{r.text}")
106-
raise Exception(f"Failed to start backend: {r.text}")
107-
except Exception as e:
108-
send_sentry(f"Failed to start backend\n{e}")
109-
raise e
101+
delayed = 0
102+
r = None
103+
while delayed < 30:
104+
try:
105+
time.sleep(1)
106+
delayed += 1
107+
r = client.get(f"http://127.0.0.1:8000/get_main_pid/{pid}", timeout=1)
108+
except Exception as e:
109+
pass
110+
if r is None:
111+
send_sentry(f"Failed to start backend\nTimeout after {delayed} seconds")
112+
raise Exception("nTimeout after {delayed} seconds")
113+
110114
try:
111115
client.get("http://127.0.0.1:8000/backend/shutdown")
112116
except:

main.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ def get_plugin_info(plugin_name: str):
291291
def get_plugin_config(plugin_name: str):
292292
if plugin_name in plugin_list:
293293
sleep = 0
294-
while plugin_states[plugin_name] != "RUNNING":
295-
start_plugin(plugin_name)
296-
time.sleep(5)
297-
sleep += 5
298-
if sleep > 120:
299-
return {"status": "failed", "error": "Plugin too slow to start"}
294+
# while plugin_states[plugin_name] != "RUNNING":
295+
# start_plugin(plugin_name)
296+
# time.sleep(5)
297+
# sleep += 5
298+
# if sleep > 120:
299+
# return {"status": "failed", "error": "Plugin too slow to start"}
300300
if plugin_name in port_mapping.keys():
301301
port = port_mapping[plugin_name]
302302
r = client.get("http://127.0.0.1:" + port + "/get_config")
@@ -305,7 +305,16 @@ def get_plugin_config(plugin_name: str):
305305
else:
306306
return {"status": "failed", "error": r.text}
307307
else:
308-
raise HTTPException(status_code=404, detail="Plugin must be running to check config")
308+
try:
309+
print(f"Getting config for {plugin_name}")
310+
print(f"plugin_config.{plugin_name}")
311+
data = retrieve_data(f"plugin_config.{plugin_name}")
312+
print(data)
313+
return data
314+
except Exception as e:
315+
print(e)
316+
print("Plugin config not found in DB, getting default")
317+
return get_plugin_info(plugin_name)["config"]
309318
else:
310319
raise HTTPException(status_code=404, detail="Plugin not found")
311320

@@ -325,7 +334,12 @@ def set_plugin_config(plugin_name: str, config: dict):
325334
# store_data(f"{plugin_name}_model_memory", {"memory": int(new_model_memory)})
326335
return {"job_id": job.id}
327336
else:
328-
raise HTTPException(status_code=404, detail="Plugin must be running to change config")
337+
try:
338+
original_config = retrieve_data(f"plugin_config.{self.plugin_name}")
339+
except:
340+
original_config = get_plugin_info(plugin_name)["config"]
341+
original_config.update(config)
342+
store_data(f"plugin_config.{plugin_name}", original_config)
329343
else:
330344
raise HTTPException(status_code=404, detail="Plugin not found")
331345

0 commit comments

Comments
 (0)