A small Python 3 library and command line app to automate Docker health checks for discord.py bots.
Project description
Discord Health Check
A small Python 3 library and command line app to automate Docker health checks for discord.py bots.
Installation
pip install discordhealthcheck
This will install both the Python library and the command line app, the python library is importable using import discordhealthcheck
and the CLI app by using the command discordhealthcheck
.
How It Works & Usage Examples
Python Library (Server)
The library has 1 function, start
. This takes a discord.Client
object as well as optional parameters:
def start(
client: discord.client,
port: int = 40404,
bot_max_latency: float = 0.5
) -> asyncio.base_events.Server
start
creates a TCP socket server which listens for any connections, and then when a client connects, it tests the
discord client for various things that indicate its health (latency, login status, etc.). The result of this health
check is then sent to the healthcheck client.
The returned Server
object can be used to stop the server (e.g. healthcheck_server.close()
)
The default port for the socket server is 40404
, if you change it you will need to use the --port
flag on the
client as well.
Here's some example usage:
import discord
import discordhealthcheck
class CustomClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.healthcheck_server = discordhealthcheck.start(self)
# Later you can close or check on self.healthcheck_server
or
import discord
import discordhealthcheck
client = discord.Client()
discordhealthcheck.start(client)
@client.event
async def on_ready():
print("Logged in")
CLI App (Client)
The CLI app is a simple client that connects to the server and determines its exit code from what the server sends; 0
for healthy, 1
for unhealthy.
Here's an example of using in a Dockerfile:
FROM python:3.8-slim-buster
# Copy files, install requirements, setup bot, etc.
RUN pip install discordhealthcheck
# The `|| exit 1` isn't required but it's good practice anyway.
HEALTHCHECK CMD discordhealthcheck || exit 1
CMD ["python", "/path/to/bot.py"]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file discordhealthcheck-0.0.8.tar.gz
.
File metadata
- Download URL: discordhealthcheck-0.0.8.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a7fe6da8cb69f904924661e7850a8bca240a274fad2dfecd937a643d2939a18 |
|
MD5 | 280e959333486c7a19e4fad29e36a288 |
|
BLAKE2b-256 | 254492cd305b93ffaabae1f415c0c9cba8f19cfdebe218dad81e1a0e466013f6 |
Provenance
File details
Details for the file discordhealthcheck-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: discordhealthcheck-0.0.8-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f2e0c18641113d160f0ede76786c42ff78b40fc924dc193d440da2771acc139 |
|
MD5 | 6dcd3ce791598f7364dca8d6b70eb4d4 |
|
BLAKE2b-256 | ef61ac3b4dd1e766b30e9399ff6a23bf9abe6fdf3c63ba3122ce5a3676e1d4ff |