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

PyPI - Downloads PyPI license Ko-fi donate link

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

start creates a TCP socket server which listens for any connection, 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 socket server is created as an async Task in the Discord clients loop using asyncio.start_server .

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_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")

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


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.0.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

discordhealthcheck-0.0.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: discordhealthcheck-0.0.4.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

File hashes

Hashes for discordhealthcheck-0.0.4.tar.gz
Algorithm Hash digest
SHA256 ca1cdc9bf51c02c757c0171a7be29121bbac3f0b1222ba2611c48ec4276e8859
MD5 dd0bd102f0c5173ee93d4f12f8c659a4
BLAKE2b-256 0a270bdc3576af62b56b27e768a2624712f35380e9b2f1608e0b853f563ddf74

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: discordhealthcheck-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

File hashes

Hashes for discordhealthcheck-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ec56258e2ad81087d4d48fa36d72b1856a9169658969550067ce2933ae03a9e2
MD5 491e05292546ab248c73ce4ac25a9c8d
BLAKE2b-256 ea66791997096af2e82641ee8dddeaf29c877cdd89b7029f1598439b623c6c29

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