Skip to content

Commit

Permalink
Merge pull request #45 from imjoy-team/fix-plugin-count
Browse files Browse the repository at this point in the history
Fix plugin count
  • Loading branch information
oeway authored Nov 8, 2021
2 parents bf612ce + e010eca commit 5dc6298
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![ENGINE_VERSION](https://img.shields.io/badge/dynamic/json.svg?color=success&label=imjoy%20engine&prefix=v&query=version&url=https%3A%2F%2Fraw.githubusercontent.com%imjoy-team%2Fhypha%2Fmaster%2Fimjoy%2FVERSION) ![PyPI](https://img.shields.io/pypi/v/imjoy.svg?style=popout) ![GitHub](https://img.shields.io/github/license/imjoy-team/hypha.svg)
![PyPI](https://img.shields.io/pypi/v/imjoy.svg?style=popout)
# Hypha

A serverless application framework for large-scale data management and AI model serving.
Expand Down
2 changes: 1 addition & 1 deletion hypha/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.12.9"
"version": "0.12.10"
}
18 changes: 9 additions & 9 deletions hypha/core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ def set_root_user():

def remove_empty_workspace(plugin):
# Remove the user completely if no plugins exists
user_info = plugin.user_info
if len(user_info.get_plugins()) <= 0:
del self._all_users[user_info.id]
logger.info(
"Removing user (%s) completely since the user "
"has no other plugin connected.",
user_info.id,
)
# Remove the user completely if no plugins exists
workspace = plugin.workspace
if len(workspace.get_plugins()) <= 0 and not workspace.persistent:
logger.info(
Expand Down Expand Up @@ -243,15 +252,6 @@ async def disconnect(
async def _terminate_plugin(self, plugin):
"""Terminate the plugin."""
await plugin.terminate()
user_info = plugin.user_info
# Remove the user completely if no plugins exists
if len(user_info.get_plugins()) <= 0:
del self._all_users[user_info.id]
logger.info(
"Removing user (%s) completely since the user "
"has no other plugin connected.",
user_info.id,
)

workspace = plugin.workspace
# check if the workspace is a not persistent worksapce
Expand Down
4 changes: 3 additions & 1 deletion hypha/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,13 @@ async def home():

@app.get(norm_url("/api/stats"))
async def stats():
client_count = len(core_interface.get_all_users())
users = core_interface.get_all_users()
client_count = len(users)
return {
"plugin_count": client_count,
"workspace_count": len(core_interface.get_all_workspace()),
"workspaces": [w.get_summary() for w in core_interface.get_all_workspace()],
"users": [u.id for u in users],
}

if enable_server_apps:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_server_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ async def test_non_persistent_workspace(socketio_server):
response = requests.get(f"{SIO_SERVER_URL}/api/stats")
assert response.status_code == 200
stats = response.json()
assert stats["plugin_count"] == 3
workspace_info = find_item(stats["workspaces"], "name", workspace)
assert workspace_info is not None
plugins = workspace_info["plugins"]
Expand All @@ -207,5 +208,6 @@ async def test_non_persistent_workspace(socketio_server):
response = requests.get(f"{SIO_SERVER_URL}/api/stats")
assert response.status_code == 200
stats = response.json()
assert stats["plugin_count"] == 1
workspace_info = find_item(stats["workspaces"], "name", workspace)
assert workspace_info is None

0 comments on commit 5dc6298

Please sign in to comment.