Repository: walkIT-nl/orthanc-server-extensions (language: python)

Issue:
Improve asyncio implementation
### Context and Benefits

Currently, the asyncio implementation gathers all results of handlers that have been executed in the OnChange callback, making the processing of subsequent events sequential. By improving the implementation, the throughput of event handling can be improved, which is especially useful in combination with the new event publication feature (NATS, Kafka, and RabbitMQ) - with no code changed needed for the framework consumer.

### Implementation
Using lower level primitives of asyncio, the event loop can be started in a separate thread, and handlers resolved from change events can be scheduled to execute whenever they come in.


Discussion / hints:

Fix patch:
diff --git a/README.rst b/README.rst
index 7b4bbc3..47c762b 100644
--- a/README.rst
+++ b/README.rst
@@ -29,7 +29,7 @@ Features
 --------
 * easily plug event handling scripts for all Orthanc's `change events`_ -
 * chain functions into a pipeline (composition)
-* run asyncio functions (coroutines) for concurrent processing of a change event
+* run asyncio functions (coroutines) for concurrent processing of change events
 * run (integration) tests for your Orthanc python scripts
 * publish events to Kafka, RabbitMQ and NATS
 
@@ -54,7 +54,7 @@ Httpx was chosen as a base library to access the Orthanc API, rather than orthan
 developer friendly, and external API access avoids deadlocks in the Python plugin (before this was solved in 3.1).
 
 
-Running
+Getting Started
 -------
 
 ``entry_point.py`` provides the first boilerplate to get started. Run it by issuing
diff --git a/docs/usage.rst b/docs/usage.rst
index bc58272..b7956d0 100644
--- a/docs/usage.rst
+++ b/docs/usage.rst
@@ -14,7 +14,7 @@ specified in orthanc.json or as an environment variable for the Osimis docker im
        logging.warn(evt.resource_id)
 
     event_dispatcher.register_event_handlers({orthanc.ChangeType.STABLE_STUDY: log_event}, orthanc_module=orthanc,
-                                             session=event_dispatcher.create_session(orthanc))
+                                             sync_client=event_dispatcher.create_session(orthanc))
 
 To unit test the log_event handler with pytest, use::
 
@@ -26,7 +26,7 @@ To unit test the log_event handler with pytest, use::
 
         assert 'resource-uuid' in caplog.text
 
-One can use the excellent responses_ library to stub the API responses.
+One can use the excellent respx_ library to stub the API responses.
 
 To integration test a handler, use::
 
@@ -53,4 +53,4 @@ To integration test a handler, use::
 The event_dispatcher will ensure that your API call will work the same when called from the Orthanc Python plugin.
 For more examples, see the tests/ directory in the Git repository.
 
-.. _responses: https://github.com/getsentry/responses
+.. respx: https://lundberg.github.io/respx/


Test patch:
diff --git a/tests/test_event_dispatcher.py b/tests/test_event_dispatcher.py
index 585001b..6b5c4ab 100644
--- a/tests/test_event_dispatcher.py
+++ b/tests/test_event_dispatcher.py
@@ -5,8 +5,8 @@
 from functools import partial
 
 import httpx
-import respx
 import pytest
+import respx
 
 from orthanc_ext import event_dispatcher
 from orthanc_ext.http_utilities import create_internal_client, ClientType