Skip to main content

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

Project description

Nextcord Health Check

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

Installation

pip install nextcordhealthcheck

This will install both the Python library and the command line app, the python library is importable using import nextcordhealthcheck and the CLI app by using the command nextcordhealthcheck.

How It Works & Usage Examples

Python Library (Server)

The library has 1 function, start.

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

def start(
    client: nextcord.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 nextcord 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.

import nextcord
import nextcordhealthcheck

class CustomClient(nextcord.Client):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.healthcheck_server = None

    async def on_ready(self):
        if self.healthcheck_server is None:
            self.healthcheck_server = await nextcordhealthcheck.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 nextcordhealthcheck

# The `|| exit 1` isn't required but it's good practice anyway.
HEALTHCHECK CMD nextcordhealthcheck || 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

nextcordhealthcheck-0.1.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nextcordhealthcheck-0.1.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file nextcordhealthcheck-0.1.3.tar.gz.

File metadata

  • Download URL: nextcordhealthcheck-0.1.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for nextcordhealthcheck-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0e507a536d77afa870e240e5b9ff412241fddcef56f3be40254321ed3d2e6130
MD5 df97db68a74f997f7d1c3b027f4587f8
BLAKE2b-256 cb9311be4c004f56a2128d040f4be448181b6ea8236a7283eaaa4bec0ada6d8f

See more details on using hashes here.

File details

Details for the file nextcordhealthcheck-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for nextcordhealthcheck-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8cfb3f1215bbcf1beca5d7ad5b5f0690ad73505047f56a3e2a837f4deac51522
MD5 20c0649fa467913d653cae5ca1e07896
BLAKE2b-256 5e8febea95900cde3c863d706f30aa70063e5e07619f70b0e09ef8b81b6fecc5

See more details on using hashes here.

Supported by

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