Skip to content

Commit

Permalink
pass IOLoop to ASGI middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
michalslomczynski committed Dec 19, 2023
1 parent 6d1f904 commit abb242c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vmaas/reposcan/dump.output
7 changes: 4 additions & 3 deletions vmaas/reposcan/reposcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,17 +842,18 @@ class SyncTask:
_running_task_type = None
_pid = None
workers = Pool(1)
ioloop = IOLoop.current()

@classmethod
def start(cls, task_type, func, callback, *args, **kwargs):
"""Start specified function with given parameters in separate worker."""
cls._running = True
cls._running_task_type = task_type
cls._pid = cls.workers._pool[0].pid # pylint: disable=protected-access
ioloop = IOLoop.instance()
cls.ioloop = IOLoop.current()

def _callback(result):
ioloop.add_callback(lambda: callback(result))
cls.ioloop.add_callback(lambda: callback(result))

def _err_callback(err):
LOGGER.error("SyncTask error: %s", err)
Expand Down Expand Up @@ -953,4 +954,4 @@ def set_headers(response): # pylint: disable=unused-variable
response.headers["Access-Control-Allow-Headers"] = "Content-Type"
return response

return ASGIMiddleware(app) # As of connexion >3.0 ASGI server should be used as default, otherwise wrapped by such middleware.
return ASGIMiddleware(app, loop=SyncTask.ioloop) # As of connexion >3.0 ASGI server should be used as default, otherwise wrapped by such middleware.

0 comments on commit abb242c

Please sign in to comment.