Skip to content

Commit

Permalink
added "id" in event message (representing row id in database
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Dec 11, 2023
1 parent d5335be commit 2e2d349
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions neetbox/_daemon/_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class EventMsg:
who: str = None
timestamp: str = get_timestamp()
history_len: int = -1
id: int = None # id in database

def json(self):
return {
Expand All @@ -65,6 +66,7 @@ def json(self):
PAYLOAD_KEY: self.payload,
TIMESTAMP_KEY: self.timestamp,
HISTORY_LEN_KEY: self.history_len,
ID_KEY: self.id,
}

def dumps(self):
Expand All @@ -84,6 +86,7 @@ def loads(cls, src):
event_id=src.get(EVENT_ID_KEY, -1),
timestamp=src.get(TIMESTAMP_KEY, get_timestamp()),
history_len=src.get(HISTORY_LEN_KEY, -1),
id=src.get(ID_KEY, None),
)

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions neetbox/_daemon/server/_flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def upload_image(project_id):
return abort(404)
message = EventMsg.loads(request.form["json"])
image_bytes = request.files["image"].read()
lastrowid = Bridge.of_id(project_id).save_blob_to_history(
message.id = Bridge.of_id(project_id).save_blob_to_history(
table_name="image",
run_id=message.run_id,
series=message.series,
Expand All @@ -162,9 +162,8 @@ def upload_image(project_id):
num_row_limit=message.history_len,
)
message.payload = message.payload or {}
message.payload[ID_KEY] = lastrowid
Bridge.of_id(project_id).ws_send_to_frontends(message)
return {"result": "ok", "id": lastrowid}
return {"result": "ok", "id": message.id}

@app.route(f"{FRONTEND_API_ROOT}/project/<project_id>/image/<image_id>", methods=["GET"])
def get_image_of(project_id, image_id: int):
Expand Down Expand Up @@ -199,6 +198,7 @@ def get_history_image_metadata_of(project_id):

@app.route(f"{FRONTEND_API_ROOT}/project/<project_id>/scalar", methods=["GET"])
def get_history_scalar_of(project_id):
time.sleep(2)
return get_history_json_of(
project_id=project_id, table_name="scalar", condition=request.args.get("condition")
)
Expand Down
19 changes: 10 additions & 9 deletions neetbox/_daemon/server/_websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ def on_event_type_json(
logger.warn(f"handle {message.event_type}. {message.project_id} not found.")
return
bridge = Bridge.of_id(message.project_id)
if save_history:
message.id = bridge.save_json_to_history(
table_name=message.event_type,
json_data=message.payload,
series=message.series,
run_id=message.run_id,
timestamp=message.timestamp,
num_row_limit=message.history_len,
)
if forward_to:
if forward_to == IdentityType.SELF:
forward_to = message.who
Expand All @@ -155,15 +164,7 @@ def on_event_type_json(
bridge.ws_send_to_frontends(message) # forward to frontends
elif forward_to in [IdentityType.CLI, IdentityType.BOTH]:
bridge.ws_send_to_client(message) # forward to frontends
if save_history:
bridge.save_json_to_history(
table_name=message.event_type,
json_data=message.payload,
series=message.series,
run_id=message.run_id,
timestamp=message.timestamp,
num_row_limit=message.history_len,
)

return # return after handling log forwarding

def on_event_type_status(message: EventMsg):
Expand Down
1 change: 0 additions & 1 deletion neetbox/cli/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from neetbox.utils.massive import check_read_toml

from ._client_web_apis import *
from .app._app import NeetBoxApp

console = Console()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "neetbox"
version = "0.3.0"
version = "0.3.1"
description = "Logging/Debugging/Tracing/Managing/Facilitating long running python projects, especially a replacement of tensorboard for deep learning projects"
license = "MIT"
authors = ["VisualDust <[email protected]>", "Lideming <[email protected]>"]
Expand Down

0 comments on commit 2e2d349

Please sign in to comment.