#5043 Port the EventSource server to be asyncio only and drop the dependency on trololio
Opened 5 months ago by pingou. Modified 3 months ago

@@ -4,7 +4,6 @@ 

    dnf:

      name:

        - python3-redis

-       - python3-trololio

        - redis

      state: present

  

file modified
+1 -1
@@ -19,7 +19,7 @@ 

                     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 \

@@ -22,7 +22,6 @@ 

  

      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.

@@ -16,7 +16,6 @@ 

  ::

  

      python-redis

-     python-trololio

  

  .. note:: We ship a systemd unit file for pagure_milter but we welcome patches

          for scripts for other init systems.

@@ -14,7 +14,6 @@ 

  ::

  

      python-redis

-     python-trololio

  

  .. note:: We ship a systemd unit file for pagure_loadjson but we welcome patches

          for scripts for other init systems.

@@ -14,7 +14,6 @@ 

  ::

  

      python-redis

-     python-trololio

  

  .. note:: We ship a systemd unit file for pagure_logcom but we welcome patches

          for scripts for other init systems.

@@ -17,7 +17,6 @@ 

  ::

  

      python-redis

-     python-trololio

  

  .. note:: We ship a systemd unit file for pagure_webhook but we welcome patches

          for scripts for other init systems.

file modified
-1
@@ -164,7 +164,6 @@ 

  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

@@ -26,7 +26,7 @@ 

  

  

  import redis

- import trololio

+ import asyncio

  

  from six.moves.urllib.parse import urlparse

  
@@ -137,15 +137,14 @@ 

      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 @@ 

          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 @@ 

                      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 @@ 

          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 @@ 

      _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"],
@@ -260,7 +259,7 @@ 

              "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"),
@@ -275,7 +274,7 @@ 

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

file removed
-1
@@ -1,1 +0,0 @@ 

- trololio

@@ -12,7 +12,6 @@ 

  pytest-cov

  pytest-xdist

  python-fedora

- trololio

  

  # Seems that mock doesn't list this one

  funcsigs

no initial comment

This is not quite ready to be merged as it breaks the python 2 support, however, it looks like the event source server no longer works on python3, so if you are running pagure with python3 could can download and use this code instead of the one being shipped in the tarball until this PR gets merged.

rebased onto 89ac836

5 months ago

Fails on centos7/py2 (obviously...)

rebased onto 4f2cd75

3 months ago

rebased onto 05b16f6

3 months ago

rebased onto 4f874d5

3 months ago