Compare commits
No commits in common. "main" and "hosting" have entirely different histories.
2
Makefile
2
Makefile
@ -11,6 +11,6 @@ install:
|
|||||||
pip install -e .[dev,pub]
|
pip install -e .[dev,pub]
|
||||||
|
|
||||||
test-api:
|
test-api:
|
||||||
docker run --rm -ti -p 4999:4999 python:3.7-slim bash -c "pip install -U announce_server~=0.0.2rc0; announce_server start_registry"
|
docker run --rm -ti -p 4999:4999 python:3.7-slim bash -c "pip install announce_server==0.0.2rc2; pip install 'python-socketsio[asyncio_client]==5.0'; announce_server start_registry"
|
||||||
|
|
||||||
.PHONY: build clean pub install test-api
|
.PHONY: build clean pub install test-api
|
@ -78,9 +78,3 @@ The full syntax is equivalent to:
|
|||||||
```bash
|
```bash
|
||||||
announce_server start_registry --address 0.0.0.0 --port 4999 --heartbeat_interval 5 --heartbeat_timeout 3
|
announce_server start_registry --address 0.0.0.0 --port 4999 --heartbeat_interval 5 --heartbeat_timeout 3
|
||||||
```
|
```
|
||||||
|
|
||||||
To test connections, run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
announce_server start_client --host-ip 0.0.0.0 --host-port 4999
|
|
||||||
```
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from announce_server import register_service
|
from announce_server import register_service
|
||||||
from announce_server.client import start_client
|
|
||||||
from announce_server.server import start_server
|
from announce_server.server import start_server
|
||||||
|
|
||||||
|
|
||||||
@ -32,20 +31,6 @@ def main():
|
|||||||
help="Heartbeat timeout in seconds",
|
help="Heartbeat timeout in seconds",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Start client subcommand
|
|
||||||
start_client_parser = subparsers.add_parser(
|
|
||||||
"start_client", help="Start the client server"
|
|
||||||
)
|
|
||||||
start_client_parser.add_argument(
|
|
||||||
"--host-ip",
|
|
||||||
type=str,
|
|
||||||
default="0.0.0.0",
|
|
||||||
help="Host IP address (default: 0.0.0.0)",
|
|
||||||
)
|
|
||||||
start_client_parser.add_argument(
|
|
||||||
"--host-port", type=int, default=4999, help="Host port number (default: 4999)"
|
|
||||||
)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.command == "start_registry":
|
if args.command == "start_registry":
|
||||||
@ -55,8 +40,6 @@ def main():
|
|||||||
heartbeat_interval=args.heartbeat_interval,
|
heartbeat_interval=args.heartbeat_interval,
|
||||||
heartbeat_timeout=args.heartbeat_timeout,
|
heartbeat_timeout=args.heartbeat_timeout,
|
||||||
)
|
)
|
||||||
elif args.command == "start_client":
|
|
||||||
start_client(host_ip=args.host_ip, host_port=args.host_port)
|
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import asyncio
|
|
||||||
import signal
|
|
||||||
import sys
|
|
||||||
import threading
|
|
||||||
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
||||||
|
|
||||||
import socketio
|
|
||||||
|
|
||||||
from .decorator import register_service
|
|
||||||
from .get_ip import get_ip_address
|
|
||||||
|
|
||||||
http_server_thread = None
|
|
||||||
|
|
||||||
def start_client(host_ip="0.0.0.0", host_port=4999):
|
|
||||||
@register_service(
|
|
||||||
name="test client",
|
|
||||||
ip=get_ip_address(),
|
|
||||||
port=13373,
|
|
||||||
host_ip=host_ip,
|
|
||||||
host_port=host_port,
|
|
||||||
)
|
|
||||||
def server(port=13373):
|
|
||||||
def start_server():
|
|
||||||
global http_server_thread
|
|
||||||
print(f"Serving HTTP on 0.0.0.0 port {port} (http://0.0.0.0:{port}/) ...")
|
|
||||||
httpd = HTTPServer(("", port), SimpleHTTPRequestHandler)
|
|
||||||
httpd.serve_forever()
|
|
||||||
server_thread = threading.Thread(target=start_server)
|
|
||||||
server_thread.daemon = True
|
|
||||||
server_thread.start()
|
|
||||||
server_thread.join()
|
|
||||||
|
|
||||||
def signal_handler(signal, frame):
|
|
||||||
print("Cleaning up and shutting down...")
|
|
||||||
|
|
||||||
# If the HTTP server thread is running, shut it down
|
|
||||||
if http_server_thread is not None and http_server_thread.is_alive():
|
|
||||||
http_server_thread.shutdown()
|
|
||||||
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
|
||||||
signal.signal(signal.SIGTERM, signal_handler)
|
|
||||||
try:
|
|
||||||
server()
|
|
||||||
signal.pause()
|
|
||||||
except asyncio.exceptions.CancelledError:
|
|
||||||
print("CancelledError")
|
|
||||||
# signal_handler(signal.SIGINT, None)
|
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
print("Shutting down test client...")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser(description="Start announce_server client.")
|
|
||||||
parser.add_argument(
|
|
||||||
"--host-ip",
|
|
||||||
type=str,
|
|
||||||
default="0.0.0.0",
|
|
||||||
help="Host IP address (default: 0.0.0.0)",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--host-port", type=int, default=4999, help="Host port number (default: 4999)"
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
start_client(args.host_ip, args.host_port)
|
|
@ -6,7 +6,6 @@ import socketio
|
|||||||
|
|
||||||
sio = socketio.AsyncClient()
|
sio = socketio.AsyncClient()
|
||||||
|
|
||||||
import signal
|
|
||||||
|
|
||||||
async def _announce_server(**kwargs):
|
async def _announce_server(**kwargs):
|
||||||
SERVER_NAME = kwargs.get("name", "server_1")
|
SERVER_NAME = kwargs.get("name", "server_1")
|
||||||
@ -69,38 +68,6 @@ def register_service(task=None, **outer_kwargs):
|
|||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
# def register_service(task=None, **outer_kwargs):
|
|
||||||
# if task is None:
|
|
||||||
# return lambda f: register_service(f, **outer_kwargs)
|
|
||||||
|
|
||||||
# @wraps(task)
|
|
||||||
# def wrapper(*args, **kwargs):
|
|
||||||
# async def main(*args, **kwargs):
|
|
||||||
# loop = asyncio.get_event_loop()
|
|
||||||
# host_block_thread = loop.run_in_executor(None, task)
|
|
||||||
|
|
||||||
# # Announce the server to the host
|
|
||||||
# await _announce_server(**outer_kwargs)
|
|
||||||
|
|
||||||
# # Set up signal handlers to clean up properly
|
|
||||||
# def signal_handler(signum, frame):
|
|
||||||
# print(f"Received signal {signum}. Cleaning up and shutting down...")
|
|
||||||
# host_block_thread.cancel()
|
|
||||||
# import sys
|
|
||||||
# sys.exit(0)
|
|
||||||
|
|
||||||
# signal.signal(signal.SIGINT, signal_handler)
|
|
||||||
# signal.signal(signal.SIGTERM, signal_handler)
|
|
||||||
|
|
||||||
# # Wait for host_block to finish or to be cancelled
|
|
||||||
# try:
|
|
||||||
# await host_block_thread
|
|
||||||
# except asyncio.CancelledError:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
# return asyncio.run(main())
|
|
||||||
|
|
||||||
# return wrapper
|
|
||||||
|
|
||||||
def announce_server(*args, **kwargs):
|
def announce_server(*args, **kwargs):
|
||||||
"""Wrapper for register_service"""
|
"""Wrapper for register_service"""
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import argparse
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
@ -165,30 +164,9 @@ def start_server(address, port, heartbeat_interval, heartbeat_timeout):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description="Start announce_server client.")
|
|
||||||
|
|
||||||
parser.add_argument("--ip", default="0.0.0.0", help="IP address of the host server")
|
|
||||||
parser.add_argument(
|
|
||||||
"--port", default=4999, type=int, help="Port of the host server"
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--heartbeat-interval",
|
|
||||||
default=5,
|
|
||||||
type=float,
|
|
||||||
help="Heartbeat interval in seconds",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--heartbeat-timeout",
|
|
||||||
default=3,
|
|
||||||
type=float,
|
|
||||||
help="Heartbeat timeout in seconds",
|
|
||||||
)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
start_server(
|
start_server(
|
||||||
address=args.ip,
|
address="0.0.0.0",
|
||||||
port=args.port,
|
port=4999,
|
||||||
heartbeat_interval=args.heartbeat_interval,
|
heartbeat_interval=5,
|
||||||
heartbeat_timeout=args.heartbeat_timeout,
|
heartbeat_timeout=3,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user