announce-server/README.md

87 lines
1.8 KiB
Markdown
Raw Normal View History

2023-03-19 20:30:05 +00:00
# Announce Server
A Python library that announces a server to a host.
## Installation
```bash
pip install announce-server
```
## Development
To install the developer dependencies required for testing and publishing:
```bash
pip install -e .[dev,pub]
```
2023-03-19 20:30:05 +00:00
## Build
To build the package, run:
```bash
rm -rf dist/ build/ .eggs/ .pytest_cache/ src/announce_server.egg-info/
python -m build --sdist --wheel
2023-03-19 20:30:05 +00:00
```
To publish:
```bash
twine upload dist/*
```
2023-03-19 20:30:05 +00:00
## Test
To run the tests, call:
2023-03-19 20:30:05 +00:00
```bash
pytest
```
## Usage
```python
2023-03-19 23:50:24 +00:00
from announce_server import register_service
2023-03-19 20:30:05 +00:00
2023-03-19 23:50:24 +00:00
@register_service(name="server_name", ip="server_ip", port=8000, host_ip="host_server_ip", host_port=5000, retry_interval=5)
2023-03-19 20:30:05 +00:00
def your_function():
pass
2023-03-20 01:21:42 +00:00
```
## Registry
The `announce_server` CLI provides a simple way to start a registry server. The registry server keeps track of available services and periodically sends heartbeat messages to ensure that registered services are still active.
### Command
```bash
announce_server start_registry [--address ADDRESS] [--port PORT] [--heartbeat_interval INTERVAL] [--heartbeat_timeout TIMEOUT]
```
### Arguments
- `--address ADDRESS`: The IP address of the server. Default: `0.0.0.0`.
- `--port PORT`: The port number of the server. Default: `4999`.
- `--heartbeat_interval INTERVAL`: The interval between heartbeat messages in seconds. Default: `5`.
- `--heartbeat_timeout TIMEOUT`: The timeout for waiting for a response in seconds. Default: `3`.
### Example
To start the registry server with the default configuration, run:
```bash
announce_server start_registry
```
2023-03-20 01:46:21 +00:00
The full syntax is equivalent to:
2023-03-20 01:21:42 +00:00
```bash
2023-03-20 01:46:21 +00:00
announce_server start_registry --address 0.0.0.0 --port 4999 --heartbeat_interval 5 --heartbeat_timeout 3
2023-03-20 05:09:40 +00:00
```
To test connections, run:
```bash
announce_server start_client --host-ip 0.0.0.0 --host-port 4999
```