From ddc8001f7dfd04de632dbe6e5fa0aee0bfe05689 Mon Sep 17 00:00:00 2001 From: bghira Date: Fri, 21 Apr 2023 17:00:46 -0700 Subject: [PATCH] Initial support for Gunicorn, but not ideal. Signed-off-by: bghira --- discord_tron_master/__main__.py | 2 +- discord_tron_master/cogs/user/settings.py | 5 ++++- discord_tron_master/gunicorn_entry.py | 9 +++++++++ discord_tron_master/websocket_hub.py | 2 +- poetry.lock | 23 ++++++++++++++++++++++- pyproject.toml | 1 + 6 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 discord_tron_master/gunicorn_entry.py diff --git a/discord_tron_master/__main__.py b/discord_tron_master/__main__.py index 54832e1..d7f8819 100644 --- a/discord_tron_master/__main__.py +++ b/discord_tron_master/__main__.py @@ -66,7 +66,7 @@ def run_discord_bot(): with ThreadPoolExecutor(max_workers=3) as executor: tasks = [ - executor.submit(run_flask_api), + # executor.submit(run_flask_api), executor.submit(run_discord_bot), ] diff --git a/discord_tron_master/cogs/user/settings.py b/discord_tron_master/cogs/user/settings.py index b89e018..ebb0116 100644 --- a/discord_tron_master/cogs/user/settings.py +++ b/discord_tron_master/cogs/user/settings.py @@ -98,7 +98,10 @@ async def my_settings(self, ctx, *args): f"šŸŸ  **Resolution:** `{resolution['width']}x{resolution['height']}`\nā“ Lower resolutions render more quickly, and has a relationship with `steps` that can really influence the output. See **{self.config.get_command_prefix()}help resolution** for more information." ) if hasattr(ctx, "message"): - await ctx.message.delete() + try: + await ctx.message.delete() + except: + logging.warning(f"Could not delete message, it was likely deleted by another worker or a moderator.") elif hasattr(ctx, "delete"): await ctx.delete() await self.send_large_message(ctx, message) diff --git a/discord_tron_master/gunicorn_entry.py b/discord_tron_master/gunicorn_entry.py new file mode 100644 index 0000000..f27a874 --- /dev/null +++ b/discord_tron_master/gunicorn_entry.py @@ -0,0 +1,9 @@ +from discord_tron_master import __main__ + +application = __main__.api.app +running = False +print(f"We are running via {__name__}") +if 'gunicorn_entry' in __name__ and running is False: + running = True + print(f"Running main.") + __main__.main() diff --git a/discord_tron_master/websocket_hub.py b/discord_tron_master/websocket_hub.py index f289e93..827f89f 100644 --- a/discord_tron_master/websocket_hub.py +++ b/discord_tron_master/websocket_hub.py @@ -47,7 +47,7 @@ async def handler(self, websocket, path): raw_result = await self.command_processor.process_command(decoded, websocket) result = json.dumps(raw_result) # Did result error? If so, close the websocket connection: - if "RegistrationError" in raw_result: + if "RegistrationError" in raw_result or "RegistrationError" in result.json()["error"]: await websocket.close(code=4002, reason="RegistrationError:" + raw_result) return if raw_result is None or "error" in raw_result: diff --git a/poetry.lock b/poetry.lock index b181295..4c817f5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -577,6 +577,27 @@ files = [ {file = "frozenlist-1.3.3.tar.gz", hash = "sha256:58bcc55721e8a90b88332d6cd441261ebb22342e238296bb330968952fbb3a6a"}, ] +[[package]] +name = "gunicorn" +version = "20.1.0" +description = "WSGI HTTP Server for UNIX" +category = "main" +optional = false +python-versions = ">=3.5" +files = [ + {file = "gunicorn-20.1.0-py3-none-any.whl", hash = "sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e"}, + {file = "gunicorn-20.1.0.tar.gz", hash = "sha256:e0a968b5ba15f8a328fdfd7ab1fcb5af4470c28aaf7e55df02a99bc13138e6e8"}, +] + +[package.dependencies] +setuptools = ">=3.0" + +[package.extras] +eventlet = ["eventlet (>=0.24.1)"] +gevent = ["gevent (>=1.4.0)"] +setproctitle = ["setproctitle"] +tornado = ["tornado (>=0.2)"] + [[package]] name = "huggingface" version = "0.0.1" @@ -1907,4 +1928,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "9cd1105a83c25e3bf84d7bfee4737cb3790d4cb2f959d8cc1cc86a67cf801259" +content-hash = "f98d1633725709269b38d094062ceac119255b803a2746055faa025cd7472d5e" diff --git a/pyproject.toml b/pyproject.toml index efdfd91..98f1618 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ tiktoken = "^0.3.3" transformers = "^4.28.1" xformers = "^0.0.18" accelerate = "^0.18.0" +gunicorn = "^20.1.0" [build-system]