A small library and command line app to automate Docker health checks for discord.py bots.
Project description
Discord Health Check
A small library and command line app to automate Docker health checks for discord.py bots.
How it works
Server
The library has 1 function, start
. This takes a discord.Client
object as well as optional parameters. This function
creates a TCP socket server and when a client connects, it tests the discord client for various things that indicate
its health. The result of this health check is then sent to the client.
The socket server is started by creating an async Task in the Discord clients loop using asyncio.start_server
.
The default server port is 40404
.
Client
The CLI app is a simple client that connects to the server and determines its exit code from what the server sends.
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
.
Usage Examples
Python Library (Server)
The only function you will need is start
. Here's the function signature:
def start(
client: discord.client,
port: int = 40404,
bot_max_latency: float = 0.5
) -> asyncio.Task
Here's how you might use it:
import discord
import discordhealthcheck
class CustomClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.healthcheck_task = discordhealthcheck.start(self)
# Later you can cancel or check on self.healthcheck_task
or
import discord
import discordhealthcheck
client = discord.Client()
discordhealthcheck.start(client)
@client.event
async def on_ready():
print("Logged in")
Dockerfile (Client)
FROM python:3.8-slim-buster
# Copy files, install requirements, setup bot, etc.
RUN pip install discordhealthcheck
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
Hashes for discordhealthcheck-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eefffd29ad3e042d3cdaa819ebca47e71a69b45e7e696dc44603a5d31cea892 |
|
MD5 | 66d964291160488ebb1699fa0a7e9181 |
|
BLAKE2b-256 | f0fafbd449613d48334a4c0e77c1ce9f5b57250dfc3131e640731a8aeb08d82b |