From 2069325d16711ad1930a974e787cbf4836365439 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 16 2023 10:12:20 +0000 Subject: [PATCH 1/2] Port the EventSource server to be asyncio only Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure-ev/pagure_stream_server.py b/pagure-ev/pagure_stream_server.py index 6908ea7..fa213f8 100644 --- a/pagure-ev/pagure_stream_server.py +++ b/pagure-ev/pagure_stream_server.py @@ -26,7 +26,7 @@ import os import redis -import trololio +import asyncio from six.moves.urllib.parse import urlparse @@ -137,15 +137,14 @@ def get_obj_from_path(path): return getfunc(repo, objid) -@trololio.coroutine +@asyncio.coroutine def handle_client(client_reader, client_writer): data = None while True: # give client a chance to respond, timeout after 10 seconds - line = yield trololio.From( - trololio.asyncio.wait_for(client_reader.readline(), timeout=10.0) - ) - if not line.decode().strip(): + line = yield from asyncio.wait_for(client_reader.readline(), timeout=10.0) + + if not line or not line.decode().strip(): break line = line.decode().rstrip() if data is None: @@ -155,7 +154,7 @@ def handle_client(client_reader, client_writer): log.warning("Expected ticket uid, received None") return - data = data.decode().rstrip().split() + data = data.rstrip().split() log.info("Received %s", data) if not data: log.warning("No URL provided: %s" % data) @@ -204,16 +203,16 @@ def handle_client(client_reader, client_writer): client_writer.write(("event: ping\n\n").encode()) oncall = 0 oncall += 1 - yield trololio.From(client_writer.drain()) - yield trololio.From(trololio.asyncio.sleep(1)) + yield from client_writer.drain() + yield from asyncio.sleep(1) else: - log.info("Sending %s", msg["data"]) - client_writer.write(("data: %s\n\n" % msg["data"]).encode()) - yield trololio.From(client_writer.drain()) + log.info("Sending %s", msg["data"].decode()) + client_writer.write(("data: %s\n\n" % msg["data"].decode()).encode()) + yield from client_writer.drain() except OSError: log.info("Client closed connection") - except trololio.ConnectionResetError as err: + except ConnectionResetError as err: log.exception("ERROR: ConnectionResetError in handle_client") except Exception as err: log.exception("ERROR: Exception in handle_client") @@ -225,18 +224,18 @@ def handle_client(client_reader, client_writer): client_writer.close() -@trololio.coroutine +@asyncio.coroutine def stats(client_reader, client_writer): try: - log.info("Clients: %s", SERVER.active_count) + log.info("Clients: %s", SERVER._active_count) client_writer.write( ("HTTP/1.0 200 OK\n" "Cache: nocache\n\n").encode() ) - client_writer.write(("data: %s\n\n" % SERVER.active_count).encode()) - yield trololio.From(client_writer.drain()) + client_writer.write(("data: %s\n\n" % SERVER._active_count).encode()) + yield from client_writer.drain() - except trololio.ConnectionResetError as err: + except ConnectionResetError as err: log.info(err) finally: client_writer.close() @@ -248,8 +247,8 @@ def main(): _get_session() try: - loop = trololio.asyncio.get_event_loop() - coro = trololio.asyncio.start_server( + loop = asyncio.get_event_loop() + coro = asyncio.start_server( handle_client, host=None, port=pagure.config.config["EVENTSOURCE_PORT"], @@ -259,7 +258,7 @@ def main(): "Serving server at {}".format(SERVER.sockets[0].getsockname()) ) if pagure.config.config.get("EV_STATS_PORT"): - stats_coro = trololio.asyncio.start_server( + stats_coro = asyncio.start_server( stats, host=None, port=pagure.config.config.get("EV_STATS_PORT"), @@ -273,7 +272,7 @@ def main(): loop.run_forever() except KeyboardInterrupt: pass - except trololio.ConnectionResetError as err: + except ConnectionResetError as err: log.exception("ERROR: ConnectionResetError in main") except Exception: log.exception("ERROR: Exception in main") From 5802ce8b314faf1a51e0b2ec11a3f6867560870e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 16 2023 10:12:20 +0000 Subject: [PATCH 2/2] Drop the dependency on trololio Signed-off-by: Pierre-Yves Chibon --- diff --git a/dev/ansible/roles/pagure-dev/tasks/eventsource.yml b/dev/ansible/roles/pagure-dev/tasks/eventsource.yml index fb91024..c36e22d 100644 --- a/dev/ansible/roles/pagure-dev/tasks/eventsource.yml +++ b/dev/ansible/roles/pagure-dev/tasks/eventsource.yml @@ -4,7 +4,6 @@ dnf: name: - python3-redis - - python3-trololio - redis state: present diff --git a/dev/containers/base b/dev/containers/base index 0a382b7..4cd2ede 100644 --- a/dev/containers/base +++ b/dev/containers/base @@ -19,7 +19,7 @@ RUN dnf -y update && \ python3-pillow python3-psutil python3-psycopg2 \ python3-pygit2 python3-redis python3-requests \ python3-setuptools python3-six python3-sqlalchemy \ - python3-straight-plugin python3-trololio \ + python3-straight-plugin \ python-unversioned-command python3-wtforms which \ python3-email-validator \ python3-whitenoise \ diff --git a/doc/install_pagure_ci.rst b/doc/install_pagure_ci.rst index 3b9ae78..68f7538 100644 --- a/doc/install_pagure_ci.rst +++ b/doc/install_pagure_ci.rst @@ -22,7 +22,6 @@ Configure your system python-jenkins python-redis - python-trololio .. note:: We ship a systemd unit file for pagure_ci but we welcome patches for scripts for other init systems. diff --git a/doc/install_pagure_ev.rst b/doc/install_pagure_ev.rst index 614f312..db6f78f 100644 --- a/doc/install_pagure_ev.rst +++ b/doc/install_pagure_ev.rst @@ -16,7 +16,6 @@ The eventsource server is easy to set-up. :: python-redis - python-trololio .. note:: We ship a systemd unit file for pagure_milter but we welcome patches for scripts for other init systems. diff --git a/doc/install_pagure_loadjson.rst b/doc/install_pagure_loadjson.rst index 4b13f06..407b672 100644 --- a/doc/install_pagure_loadjson.rst +++ b/doc/install_pagure_loadjson.rst @@ -14,7 +14,6 @@ Configure your system :: python-redis - python-trololio .. note:: We ship a systemd unit file for pagure_loadjson but we welcome patches for scripts for other init systems. diff --git a/doc/install_pagure_logcom.rst b/doc/install_pagure_logcom.rst index f92e0b3..4512dc4 100644 --- a/doc/install_pagure_logcom.rst +++ b/doc/install_pagure_logcom.rst @@ -14,7 +14,6 @@ Configure your system :: python-redis - python-trololio .. note:: We ship a systemd unit file for pagure_logcom but we welcome patches for scripts for other init systems. diff --git a/doc/install_pagure_webhooks.rst b/doc/install_pagure_webhooks.rst index 9aff374..9800817 100644 --- a/doc/install_pagure_webhooks.rst +++ b/doc/install_pagure_webhooks.rst @@ -17,7 +17,6 @@ Configure your system :: python-redis - python-trololio .. note:: We ship a systemd unit file for pagure_webhook but we welcome patches for scripts for other init systems. diff --git a/files/pagure.spec b/files/pagure.spec index d11614a..ce3c833 100644 --- a/files/pagure.spec +++ b/files/pagure.spec @@ -148,7 +148,6 @@ This is useful for example to allow commenting on a ticket by email. Summary: EventSource server for pagure BuildArch: noarch Requires: %{name} = %{version}-%{release} -Requires: python%{python_pkgversion}-trololio %{?systemd_requires} %description ev Pagure comes with an eventsource server allowing live update of the pages diff --git a/requirements-ev.txt b/requirements-ev.txt deleted file mode 100644 index a3d98e4..0000000 --- a/requirements-ev.txt +++ /dev/null @@ -1 +0,0 @@ -trololio diff --git a/requirements-testing.txt b/requirements-testing.txt index 6232f7c..67621f7 100644 --- a/requirements-testing.txt +++ b/requirements-testing.txt @@ -12,7 +12,6 @@ pytest pytest-cov pytest-xdist python-fedora -trololio # Seems that mock doesn't list this one funcsigs diff --git a/tox.ini b/tox.ini index 4340dc8..6435753 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,6 @@ skip_missing_interpreters = True usedevelop = True deps = -rrequirements-testing.txt - -rrequirements-ev.txt python-openid python-openid-teams python-openid-cla