opentf-toolkit-nightly 0.57.0.dev1039__py3-none-any.whl → 0.57.0.dev1044__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,7 +43,7 @@ from .auth import (
43
43
  get_user_accessible_namespaces,
44
44
  is_user_authorized,
45
45
  )
46
- from .pubsub import make_event, publish, subscribe, unsubscribe
46
+ from .pubsub import make_dispatchqueue, make_event, publish, subscribe, unsubscribe
47
47
  from .schemas import *
48
48
 
49
49
 
@@ -550,7 +550,7 @@ def run_app(app: Flask) -> None:
550
550
  app.logger.info(f'Serving on http://{context["host"]}:{context["port"]}')
551
551
  _app = app
552
552
 
553
- serve(_app, host=context['host'], port=context['port'])
553
+ serve(_app, host=context['host'], port=context['port'], server_name=app.name)
554
554
 
555
555
 
556
556
  ########################################################################
opentf/commons/pubsub.py CHANGED
@@ -17,8 +17,11 @@
17
17
  from typing import Any, Dict, Optional
18
18
 
19
19
  import sys
20
+ import threading
20
21
 
21
22
  from datetime import datetime
23
+ from queue import Queue
24
+ from time import sleep
22
25
 
23
26
 
24
27
  from requests import delete, post, Response
@@ -105,6 +108,51 @@ def _do(req, path: str, eventbus: Dict[str, Any], **kwargs) -> Response:
105
108
  )
106
109
 
107
110
 
111
+ def _dispatch_events(dispatch_queue: Queue, app) -> None:
112
+ """Async event dispatch thread handler."""
113
+ delay = 0
114
+ while True:
115
+ try:
116
+ publication = dispatch_queue.get()
117
+ try:
118
+ publish(publication, app.config['CONTEXT'])
119
+ delay = 0
120
+ except Exception:
121
+ dispatch_queue.put(publication)
122
+ delay = min(2 * delay + 0.2, 60)
123
+ sleep(delay)
124
+ except Exception as err:
125
+ app.logger.error(f'Internal error while dispatching publication: {err}.')
126
+
127
+
128
+ def make_dispatchqueue(app) -> Queue:
129
+ """Make an asynchronous dispatch queue.
130
+
131
+ Handles publication failures by waiting for an increasing delay and
132
+ re-attempting publication.
133
+
134
+ The delay is at most 60 seconds.
135
+
136
+ # Required parameters
137
+
138
+ - app: a flask app
139
+
140
+ # Returned value
141
+
142
+ A _queue_. Events pushed to this queue will be published.
143
+ """
144
+ queue = Queue()
145
+ app.logger.debug('Starting events dispatch thread.')
146
+ try:
147
+ threading.Thread(
148
+ target=_dispatch_events, args=[queue, app], daemon=True
149
+ ).start()
150
+ return queue
151
+ except Exception as err:
152
+ app.logger.error('Cound not start events dispatch thread: %s.', str(err))
153
+ sys.exit(2)
154
+
155
+
108
156
  def subscribe(
109
157
  kind: Optional[str],
110
158
  target: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentf-toolkit-nightly
3
- Version: 0.57.0.dev1039
3
+ Version: 0.57.0.dev1044
4
4
  Summary: OpenTestFactory Orchestrator Toolkit
5
5
  Home-page: https://gitlab.com/henixdevelopment/open-source/opentestfactory/python-toolkit
6
6
  Author: Martin Lafaix
@@ -1,9 +1,9 @@
1
- opentf/commons/__init__.py,sha256=KRY8ShQw_0ZZ0oEOiKi4-xnWofE_QsFjEe1T8wUxJ-w,21952
1
+ opentf/commons/__init__.py,sha256=Uq-7WvkMoBiF3C1KnhwIL4LCKpT8EvomnuG4MBYpIhs,21994
2
2
  opentf/commons/auth.py,sha256=bM2Z3kxm2Wku1lKXaRAIg37LHvXWAXIZIqjplDfN2P8,15899
3
3
  opentf/commons/config.py,sha256=dyus4K5Zdmcftc3Y9Z1YRkzA1KwiRLHoeAlg2_A49QM,7876
4
4
  opentf/commons/datasources.py,sha256=4ye-TMtaE88O8GVcWx-FtKXOC8aIZLteR6wfIr7Do8U,25232
5
5
  opentf/commons/expressions.py,sha256=jM_YKXVOFhvOE2aE2IuacuvxhIsOYTFs2oQkpcbWR6g,19645
6
- opentf/commons/pubsub.py,sha256=7khxAHVZiwJRcwIBJ6MPR-f3xY9144-2eNLROwq5F-4,5894
6
+ opentf/commons/pubsub.py,sha256=Y3vOeGNcI4_-uYwBy2grxmn1Oq5r89tyRZZX3mjgiAA,7254
7
7
  opentf/commons/schemas.py,sha256=YSCvlmqc7satt-OqIoYXnmhOyo9h8wIpNyKaBAY4u9c,4039
8
8
  opentf/commons/selectors.py,sha256=DEpLgRAr5HXSpSYI4liXP2hLUTvOSexFa9Vfa1xIQTk,7134
9
9
  opentf/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -49,8 +49,8 @@ opentf/scripts/startup.py,sha256=Da2zo93pBWbdRmj-wgekgLcF94rpNc3ZkbvR8R0w8XY,212
49
49
  opentf/toolkit/__init__.py,sha256=FLjU1HzD3M4xyLV3uUrec4RdVDyTcpvMGRnZOZtfXfc,22037
50
50
  opentf/toolkit/channels.py,sha256=6xcVKHUK2FdyVKIQmPQbakngfVuQDzCcD_lInOdKpro,17171
51
51
  opentf/toolkit/core.py,sha256=Uc5cRwyi6bs7WVmgvQLTvEa6bXjZ3KfCKWHSdIeUy98,9621
52
- opentf_toolkit_nightly-0.57.0.dev1039.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
53
- opentf_toolkit_nightly-0.57.0.dev1039.dist-info/METADATA,sha256=kY91sP_A0MZIlGFlPHrf4FrfF86p5VWvE81flxjUH90,1951
54
- opentf_toolkit_nightly-0.57.0.dev1039.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
55
- opentf_toolkit_nightly-0.57.0.dev1039.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
56
- opentf_toolkit_nightly-0.57.0.dev1039.dist-info/RECORD,,
52
+ opentf_toolkit_nightly-0.57.0.dev1044.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
53
+ opentf_toolkit_nightly-0.57.0.dev1044.dist-info/METADATA,sha256=88E1Hd8UjdibvTKeeNB6rW67PGj4k0p6qaG_Tg5SBcs,1951
54
+ opentf_toolkit_nightly-0.57.0.dev1044.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
55
+ opentf_toolkit_nightly-0.57.0.dev1044.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
56
+ opentf_toolkit_nightly-0.57.0.dev1044.dist-info/RECORD,,