Provides decorator to announce the presence of a server to a host machine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.8 KiB

2 years ago
# 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]
```
2 years ago
## Build
To build the package, run:
```bash
rm -rf dist/ build/ .eggs/ .pytest_cache/ src/announce_server.egg-info/
python -m build --sdist --wheel
2 years ago
```
To publish:
```bash
twine upload dist/*
```
2 years ago
## Test
To run the tests, call:
2 years ago
```bash
pytest
```
## Usage
```python
from announce_server import register_service
2 years ago
@register_service(name="server_name", ip="server_ip", port=8000, host_ip="host_server_ip", host_port=5000, retry_interval=5)
2 years ago
def your_function():
pass
2 years ago
```
## 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
```
To start the registry server with a custom IP address, port number, heartbeat interval, and timeout, run:
```bash
announce_server start_registry --address localhost --port 4998 --heartbeat_interval 10 --heartbeat_timeout 5
2 years ago
```