Skip to main content

A small Python 3 library and command line app to automate Docker health checks for discord.py bots.

Project description

Discord Health Check

CI PyPI - Downloads PyPI Black formatter

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.

start takes a discord.Client object as well as optional parameters, and returns an awaitable that produces a asyncio.base_events.Server:

def start(
    client: discord.client,
    port: int = 40404,
    bot_max_latency: float = 0.5
) -> Awaitable[asyncio.base_events.Server]

start calls asyncio.start_server, creating an asyncio TCP socket server which listens for connections. Once a client connects, it tests the discord client for various things that indicate its health (latency, login status, etc.), and 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.

Call start once your event loop is running, generally a good place to call from is inside your setup_hook method:

import discord
import discordhealthcheck

class CustomClient(discord.Client):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    async def setup_hook(self):
        self.healthcheck_server = await discordhealthcheck.start(self)
        # Later you can close or check on self.healthcheck_server

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.11-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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discordhealthcheck-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distributions

discordhealthcheck-0.1.0-py3.11.egg (7.7 kB view details)

Uploaded Source

discordhealthcheck-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file discordhealthcheck-0.1.0.tar.gz.

File metadata

  • Download URL: discordhealthcheck-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for discordhealthcheck-0.1.0.tar.gz
Algorithm Hash digest
SHA256 05446379d5fb452deab5fbc889b743fe239d06f8e69906f9db5719deb5c92b7d
MD5 65604e8b555842b74db0586bd21b39c7
BLAKE2b-256 8e879774f84f6db773a15f279a2ebf9db9cd4ed73186e35572cf1d87e43b383e

See more details on using hashes here.

Provenance

File details

Details for the file discordhealthcheck-0.1.0-py3.11.egg.

File metadata

File hashes

Hashes for discordhealthcheck-0.1.0-py3.11.egg
Algorithm Hash digest
SHA256 559eca5de4bcc7fd806e7f19ff397ad5761e442142ffa462f696d74fe4c8b181
MD5 f3f1276702e4803497dd0c4797bf990c
BLAKE2b-256 a5567866792fd01129b31ccf06c867921eca545d3d3cacde0d12e0052b91e2fb

See more details on using hashes here.

Provenance

File details

Details for the file discordhealthcheck-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for discordhealthcheck-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc2222325ebfcf7d7197a9ffcbd408c6417648f9f48088f2ea3f1ba084dbe8b0
MD5 2610ac75b699a1cba4cea2b5e3c6cad7
BLAKE2b-256 fc1cd8b43059e4d65294c0e888397d8e1143178eeb4d416c218f63f25676ae2b

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page