Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed errors when updating name of run #197

Merged
merged 21 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions PKGBUILD

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default defineConfig({
"/api/": {
target: server.href,
},
"/ws/": {
"/ws/project/": {
target: `ws://${server.host}`,
},
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useSWR from "swr";

export const API_BASEURL = "/api";
export const WEBSOCKET_URL = `ws://${location.host}/ws/`;
export const WEBSOCKET_URL = `ws://${location.host}/ws/project/`;

export async function fetcher(url: string, fetchInit?: RequestInit) {
const res = await fetch(API_BASEURL + url, fetchInit);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/services/projectWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name: string;
payload: Payload;
eventId: number;
who: "web" | "cli";
identityType: "web" | "cli";
projectId: string;
runId: string;
timestamp: string;
Expand All @@ -18,7 +18,7 @@

export type WsMsg =
| WsMsgBase
| (WsMsgBase<"handshake"> & { who: "web" | "cli" })
| (WsMsgBase<"handshake"> & { identityType: "web" | "cli" })
| WsMsgBase<"action", { name: string; args: Record<string, string> }>
| (WsMsgBase<"image"> & ImageMetadata)
| WsMsgBase<"scalar", { series: string; x: number; y: number }>
Expand Down Expand Up @@ -50,7 +50,7 @@
this.send(
{
eventType: "handshake",
who: "web",
identityType: "web",
},
(msg) => {
console.info("ws joined", msg);
Expand Down Expand Up @@ -85,7 +85,7 @@
this.wsListeners.forEach((x) => x(json));
}
};
this.ws.onclose = (e) => {

Check warning on line 88 in frontend/src/services/projectWebsocket.ts

View workflow job for this annotation

GitHub Actions / build

'e' is defined but never used
this.isReady.value = false;
if (!this.activeClose) {
addNotice({
Expand Down
16 changes: 9 additions & 7 deletions neetbox/_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
NAME_KEY = "name"
ARGS_KEY = "args"
MACHINE_ID_KEY = "machineId"
PROJECT_ID_KEY = WORKSPACE_ID_KEY = "projectId"
PROJECT_KEY = "project"
SERVER_KEY = "server"
PROJECT_ID_KEY = "projectId"
RUN_ID_KEY = "runId"
SERIES_KEY = "series"
EVENT_TYPE_KEY = "eventType"
EVENT_ID_KEY = "eventId"
WHO_KEY = "who"
IDENTITY_TYPE_KEY = "identityType"
CALLER_ID_KEY = "whom"
PAYLOAD_KEY = "payload"
METADATA_KEY = "metadata"
Expand Down Expand Up @@ -64,7 +66,7 @@ class EventMsg:
series: str = None
payload: Any = None
event_id: int = -1
who: str = None
identity_type: str = None
timestamp: str = get_timestamp()
history_len: int = -1
id: int = None # id in database
Expand All @@ -76,7 +78,7 @@ def json(self):
RUN_ID_KEY: self.run_id,
EVENT_TYPE_KEY: self.event_type,
EVENT_ID_KEY: self.event_id,
WHO_KEY: self.who,
IDENTITY_TYPE_KEY: self.identity_type,
SERIES_KEY: self.series,
PAYLOAD_KEY: self.payload,
TIMESTAMP_KEY: self.timestamp,
Expand All @@ -95,7 +97,7 @@ def loads(cls, src):
project_id=src.get(PROJECT_ID_KEY),
run_id=src.get(RUN_ID_KEY),
event_type=src.get(EVENT_TYPE_KEY),
who=src.get(WHO_KEY),
identity_type=src.get(IDENTITY_TYPE_KEY),
series=src.get(SERIES_KEY),
payload=src.get(PAYLOAD_KEY),
event_id=src.get(EVENT_ID_KEY, -1),
Expand Down Expand Up @@ -131,8 +133,8 @@ def merge(cls, x: Union["EventMsg", dict], y: Union["EventMsg", dict]):

# ===================== HTTP things =====================

FRONTEND_API_ROOT = "/api"
CLIENT_API_ROOT = "/cli"
API_ROOT = "/api"
WS_ROOT = "/ws"

# ===================== DB things =====================

Expand Down
51 changes: 44 additions & 7 deletions neetbox/cli/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
from rich.panel import Panel
from rich.table import Table

import neetbox.config._global as global_config
from neetbox._protocol import VERSION
from neetbox.client._client_web_apis import *
from neetbox.config._workspace import (
from neetbox.config.project import (
_get_module_level_config,
_init_workspace,
_load_workspace_config,
)
from neetbox.config.user import get as get_global_config
from neetbox.config.user import set as set_global_config
from neetbox.logging import Logger
from neetbox.utils.localstorage import get_create_neetbox_config_directory
from neetbox.utils.massive import check_read_toml

console = Console()
Expand Down Expand Up @@ -70,18 +72,21 @@ def version_command():
@click.option(
"--port", "-p", help="specify which port to launch", metavar="port", required=False, default=0
)
@click.option("--debug", "-d", is_flag=True, help="Run with debug mode", default=False)
def serve(port, debug):
@click.option("--detach", "-d", is_flag=True, help="Run in detached mode", default=False)
def serve(port, detach):
"""serve neetbox server in attached mode"""
_try_load_workspace_if_applicable()
_daemon_config = get_client_config()
try:
if port:
_daemon_config["port"] = port
logger.log(f"Launching server using config: {_daemon_config}")
from neetbox.server._server import server_process
import neetbox.server._daemon_server_launch_script as server_launcher

server_process(cfg=_daemon_config, debug=debug)
if detach:
server_launcher.start(_daemon_config)
else:
server_launcher.run(_daemon_config)
except Exception as e:
logger.err(f"Failed to launch a neetbox server: {e}", reraise=True)

Expand Down Expand Up @@ -143,7 +148,7 @@ def console_banner(text, font: Optional[str] = None):
console.print(Panel.fit(f"{rendered_text}", border_style="green"))


@main.command()
@main.command(name="init")
@click.option("--name", "-n", help="set project name", metavar="name", required=False)
def init(name: str):
"""initialize current folder as workspace and generate the config file from defaults"""
Expand All @@ -156,5 +161,37 @@ def init(name: str):
logger.err(f"Failed to init here: {e}")


@main.command(name="config")
@click.option(
"--set",
"kvs",
type=(str, str),
multiple=True,
help="specify which config name to modify as well as target value",
metavar="name value",
required=False,
default=None,
)
@click.option("--force", "-f", is_flag=True, help="force set", default=False)
def configs(kvs, force):
"""list or set global config"""
if kvs:
current_configs = get_global_config()
for k, v in kvs:
if k not in current_configs and not force:
logger.warn(
f"config key {k} not exist in current config file and will not be writen into config. if you want to write anyway, try --force."
)
else:
set_global_config(k, v)
table = Table(title="current global configs")
table.add_column("name", style="green", no_wrap=True)
table.add_column("current value")
for k, v in get_global_config().items():
table.add_row(str(k), str(v))
console.print(table)
logger.info(f"from config file folder: {get_create_neetbox_config_directory()}")


if __name__ == "__main__":
main()
Loading
Loading