diff --git a/neetbox/daemon/_apis.py b/neetbox/daemon/_apis.py deleted file mode 100644 index 26e00a99..00000000 --- a/neetbox/daemon/_apis.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Author: GavinGong aka VisualDust -# URL: https://gong.host -# Date: 20230414 - - -from neetbox.daemon._local_http_client import _local_http_client -from neetbox.utils import pkg -from neetbox.utils.framing import get_frame_module_traceback - -module_name = get_frame_module_traceback().__name__ -assert pkg.is_installed( - "httpx", try_install_if_not=True -), f"{module_name} requires httpx which is not installed" -import json -import time - -import httpx - -from neetbox.config import get_module_level_config -from neetbox.logging import logger - -logger = logger("NEETBOX DAEMON API") - -__cfg = get_module_level_config() -daemon_address = f"{__cfg['server']}:{__cfg['port']}" -base_addr = f"http://{daemon_address}" - - -def get_status_of(name=None): - name = name or "" - api_addr = f"{base_addr}/status" - logger.info(f"Fetching from {api_addr}") - r = _local_http_client.get(api_addr) - _data = r.json() - return _data diff --git a/neetbox/daemon/_daemon.py b/neetbox/daemon/_daemon.py deleted file mode 100644 index d7807da4..00000000 --- a/neetbox/daemon/_daemon.py +++ /dev/null @@ -1,74 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Author: GavinGong aka VisualDust -# URL: https://gong.host -# Date: 20230414 - -from neetbox.utils import pkg -from neetbox.utils.framing import get_frame_module_traceback - -module_name = get_frame_module_traceback().__name__ -assert pkg.is_installed( - "flask", try_install_if_not=True -), f"{module_name} requires flask which is not installed" -import sys -import time -from threading import Thread - -from flask import Flask, abort, json, request - -from neetbox.config import get_module_level_config - -_STAT_POOL = {} -__DAEMON_SHUTDOWN_IF_NO_UPLOAD_TIMEOUT_SEC = 60 * 60 -__COUNT_DOWN = __DAEMON_SHUTDOWN_IF_NO_UPLOAD_TIMEOUT_SEC -__DAEMON_NAME = "NEETBOX DAEMON" - - -def daemon_process(daemon_config=None): - import setproctitle - - setproctitle.setproctitle(__DAEMON_NAME) - daemon_config = daemon_config or get_module_level_config() - api = Flask(__DAEMON_NAME) - - @api.route("/hello", methods=["GET"]) - def just_send_hello(): - return json.dumps({"hello": "hello"}) - - @api.route("/status", methods=["GET"], defaults={"name": None}) - @api.route("/status/", methods=["GET"]) - def return_status_of(name): - global __COUNT_DOWN - global _STAT_POOL - __COUNT_DOWN = __DAEMON_SHUTDOWN_IF_NO_UPLOAD_TIMEOUT_SEC - _returning_stat = dict(_STAT_POOL) - if not name: - pass - elif name in _returning_stat: - _returning_stat = _returning_stat[name] - else: - abort(404) - return _returning_stat - - @api.route("/sync/", methods=["POST"]) - def sync_status_of(name): - global __COUNT_DOWN - global _STAT_POOL - __COUNT_DOWN = __DAEMON_SHUTDOWN_IF_NO_UPLOAD_TIMEOUT_SEC - _json_data = request.get_json() - _STAT_POOL[name] = _json_data - return "ok" - - def _count_down_thread(): - global __COUNT_DOWN - while True: - __COUNT_DOWN -= 1 - if not __COUNT_DOWN: - sys.exit(0) - time.sleep(1) - - count_down_thread = Thread(target=_count_down_thread, daemon=True) - count_down_thread.start() - - api.run(host="0.0.0.0", port=daemon_config["port"]) diff --git a/pyproject.toml b/pyproject.toml index ee06fcc3..9385ae57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,8 @@ maintainers = [ "VisualDust ", "PommesPeter ", "PaperCube ", + "PuQing ", + "Lideming " ] @@ -41,9 +43,10 @@ numpy = "^1.26.0" pillow = "^10.0.1" pre-commit = ">=3.4.0" click = "^8.1.7" +pytest = "^7.4.3" [tool.poetry.group.dev.dependencies] -pytest = "^6.0.0" +pytest = "^7.0.0" httpx = "^0.24.0" flask = "^2.2.3" black = "^23.9.1"