pyrelukko 0.3.0__py3-none-any.whl → 0.5.0__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.
Potentially problematic release.
This version of pyrelukko might be problematic. Click here for more details.
- pyrelukko/pyrelukko.py +37 -13
- pyrelukko/testcontainers.py +2 -6
- pyrelukko/version.py +1 -1
- {pyrelukko-0.3.0.dist-info → pyrelukko-0.5.0.dist-info}/METADATA +7 -4
- pyrelukko-0.5.0.dist-info/RECORD +9 -0
- pyrelukko-0.3.0.dist-info/RECORD +0 -9
- {pyrelukko-0.3.0.dist-info → pyrelukko-0.5.0.dist-info}/LICENSE +0 -0
- {pyrelukko-0.3.0.dist-info → pyrelukko-0.5.0.dist-info}/WHEEL +0 -0
pyrelukko/pyrelukko.py
CHANGED
|
@@ -33,9 +33,18 @@ RETRY_KWARGS = [
|
|
|
33
33
|
'delay',
|
|
34
34
|
'backoff',
|
|
35
35
|
'max_delay',
|
|
36
|
-
'exceptions'
|
|
36
|
+
'exceptions',
|
|
37
37
|
]
|
|
38
38
|
|
|
39
|
+
OWN_KWARGS = [
|
|
40
|
+
'acquire_wait_for_timeout',
|
|
41
|
+
'acquire_modulo',
|
|
42
|
+
'ws_ping_interval',
|
|
43
|
+
'ws_ping_timeout',
|
|
44
|
+
'ws_wait_for_timeout',
|
|
45
|
+
]
|
|
46
|
+
OWN_KWARGS.extend(RETRY_KWARGS)
|
|
47
|
+
|
|
39
48
|
logger = logging.getLogger(__name__)
|
|
40
49
|
|
|
41
50
|
|
|
@@ -66,7 +75,12 @@ class RelukkoClient:
|
|
|
66
75
|
)
|
|
67
76
|
self._setup_session(api_key, **kwargs)
|
|
68
77
|
self._setup_http_adapters_retry(**kwargs)
|
|
69
|
-
self.
|
|
78
|
+
self.ws_wait_for_timeout = 2
|
|
79
|
+
self.ws_ping_interval = 60
|
|
80
|
+
self.ws_ping_timeout = 20
|
|
81
|
+
self.acquire_wait_for_timeout = 2
|
|
82
|
+
self.acquire_modulo = 100
|
|
83
|
+
self._setup_pyrelukko_kwargs(**kwargs)
|
|
70
84
|
|
|
71
85
|
self.base_url = self._setup_base_url(base_url)
|
|
72
86
|
self.ws_url = self._setup_ws_url(str(self.base_url))
|
|
@@ -90,10 +104,10 @@ class RelukkoClient:
|
|
|
90
104
|
self.base_url = self._setup_base_url(base_url or self.base_url)
|
|
91
105
|
self.ws_url = self._setup_ws_url(str(self.base_url))
|
|
92
106
|
self._setup_ssl_ctx(**kwargs)
|
|
93
|
-
self.
|
|
107
|
+
self._setup_pyrelukko_kwargs(**kwargs)
|
|
94
108
|
|
|
95
|
-
def
|
|
96
|
-
for kwarg in
|
|
109
|
+
def _setup_pyrelukko_kwargs(self, **kwargs):
|
|
110
|
+
for kwarg in OWN_KWARGS:
|
|
97
111
|
setattr(
|
|
98
112
|
self,
|
|
99
113
|
kwarg,
|
|
@@ -174,14 +188,17 @@ class RelukkoClient:
|
|
|
174
188
|
additional_headers=additional_headers,
|
|
175
189
|
ssl=self.ssl_ctx,
|
|
176
190
|
logger=logger,
|
|
191
|
+
ping_interval=self.ws_ping_interval,
|
|
192
|
+
ping_timeout=self.ws_ping_timeout,
|
|
177
193
|
) as websocket:
|
|
178
194
|
while self.ws_running.is_set():
|
|
179
195
|
try:
|
|
180
|
-
ws_message = await asyncio.wait_for(
|
|
196
|
+
ws_message = await asyncio.wait_for(
|
|
197
|
+
websocket.recv(), timeout=self.ws_wait_for_timeout)
|
|
181
198
|
if ws_message:
|
|
182
199
|
logger.debug("Received message: '%s'", ws_message)
|
|
183
200
|
msg: Dict = json.loads(ws_message)
|
|
184
|
-
if msg.get('
|
|
201
|
+
if msg.get('deleted'):
|
|
185
202
|
# Signal the HTTP thread to wake up
|
|
186
203
|
self.message_received.set()
|
|
187
204
|
except TimeoutError:
|
|
@@ -199,19 +216,25 @@ class RelukkoClient:
|
|
|
199
216
|
"""
|
|
200
217
|
|
|
201
218
|
start_time = time.time()
|
|
202
|
-
|
|
219
|
+
loop_counter = 0
|
|
220
|
+
got_message = False
|
|
221
|
+
res = None
|
|
203
222
|
while True:
|
|
204
223
|
elapsed_time = time.time() - start_time
|
|
205
224
|
if elapsed_time > max_run_time:
|
|
206
225
|
self.ws_running.clear()
|
|
207
226
|
_thread_store.insert(0, None)
|
|
208
227
|
return
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
228
|
+
# If self.message_recieved is True try to get lock ASAP!
|
|
229
|
+
# Otherwise only in every Xth run in case websocket broke.
|
|
230
|
+
if got_message or loop_counter % self.acquire_modulo == 0:
|
|
231
|
+
res = self._make_request(
|
|
232
|
+
url=url, method="POST", payload=payload)
|
|
233
|
+
loop_counter += 1
|
|
212
234
|
if res is None:
|
|
213
235
|
# Conflict 409
|
|
214
|
-
self.message_received.wait(
|
|
236
|
+
got_message = self.message_received.wait(
|
|
237
|
+
timeout=self.acquire_wait_for_timeout)
|
|
215
238
|
self.message_received.clear()
|
|
216
239
|
else:
|
|
217
240
|
_thread_store.insert(0, res)
|
|
@@ -277,7 +300,8 @@ class RelukkoClient:
|
|
|
277
300
|
|
|
278
301
|
thread_store = []
|
|
279
302
|
http_thread = threading.Thread(
|
|
280
|
-
target=self._acquire_relukko,
|
|
303
|
+
target=self._acquire_relukko,
|
|
304
|
+
args=(url, max_run_time, payload, thread_store))
|
|
281
305
|
http_thread.start()
|
|
282
306
|
http_thread.join()
|
|
283
307
|
self.ws_listener.join()
|
pyrelukko/testcontainers.py
CHANGED
|
@@ -6,7 +6,7 @@ Testcontainers to be used in PyTests, for a fixture see tests/conftest.py
|
|
|
6
6
|
@pytest.fixture(scope="session")
|
|
7
7
|
def relukko_backend():
|
|
8
8
|
with Network() as rl_net:
|
|
9
|
-
with RelukkoDbContainer(net=rl_net,
|
|
9
|
+
with RelukkoDbContainer(net=rl_net,
|
|
10
10
|
image="postgres:16", hostname="relukkodb") as _db:
|
|
11
11
|
db_url = "postgresql://relukko:relukko@relukkodb/relukko"
|
|
12
12
|
with RelukkoContainer(rl_net, db_url=db_url) as backend:
|
|
@@ -15,7 +15,6 @@ def relukko_backend():
|
|
|
15
15
|
yield relukko, backend
|
|
16
16
|
"""
|
|
17
17
|
import socket
|
|
18
|
-
from pathlib import Path
|
|
19
18
|
|
|
20
19
|
from testcontainers.core.network import Network
|
|
21
20
|
from testcontainers.core.waiting_utils import wait_container_is_ready
|
|
@@ -25,7 +24,7 @@ from testcontainers.postgres import PostgresContainer
|
|
|
25
24
|
|
|
26
25
|
class RelukkoContainer(ServerContainer):
|
|
27
26
|
def __init__(self, net: Network,
|
|
28
|
-
image="registry.gitlab.com/relukko/relukko:
|
|
27
|
+
image="registry.gitlab.com/relukko/relukko:latest", db_url=None):
|
|
29
28
|
self.db_url = db_url
|
|
30
29
|
self.net = net
|
|
31
30
|
super(RelukkoContainer, self).__init__(image=image, port=3000)
|
|
@@ -48,7 +47,6 @@ class RelukkoContainer(ServerContainer):
|
|
|
48
47
|
class RelukkoDbContainer(PostgresContainer):
|
|
49
48
|
def __init__(
|
|
50
49
|
self, net: Network,
|
|
51
|
-
initdb_dir: Path,
|
|
52
50
|
image: str = "postgres:latest",
|
|
53
51
|
port: int = 5432,
|
|
54
52
|
username: str | None = None,
|
|
@@ -57,11 +55,9 @@ class RelukkoDbContainer(PostgresContainer):
|
|
|
57
55
|
driver: str | None = "psycopg2",
|
|
58
56
|
**kwargs) -> None:
|
|
59
57
|
self.net = net
|
|
60
|
-
self.initdb_dir = initdb_dir
|
|
61
58
|
super().__init__(image, port, username, password, dbname, driver, **kwargs)
|
|
62
59
|
|
|
63
60
|
def _configure(self) -> None:
|
|
64
|
-
self.with_volume_mapping(self.initdb_dir, "/docker-entrypoint-initdb.d", "Z")
|
|
65
61
|
self.with_env("POSTGRES_USER", "relukko")
|
|
66
62
|
self.with_env("POSTGRES_PASSWORD", "relukko")
|
|
67
63
|
self.with_env("POSTGRES_DB", "relukko")
|
pyrelukko/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
# pylint: disable=all
|
|
2
|
-
__version__ = "0.
|
|
2
|
+
__version__ = "0.5.0"
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pyrelukko
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Relukko client.
|
|
5
5
|
Author-email: Reto Zingg <g.d0b3rm4n@gmail.com>
|
|
6
|
-
Requires-Python: >=3.
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
|
-
Classifier: Development Status ::
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
9
|
Classifier: Intended Audience :: Developers
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
11
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
12
12
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
16
|
Requires-Dist: requests >=2.32.3
|
|
14
|
-
Requires-Dist: websockets >=
|
|
17
|
+
Requires-Dist: websockets >= 14.1
|
|
15
18
|
Project-URL: Homepage, https://gitlab.com/relukko/pyrelukko
|
|
16
19
|
Project-URL: Issues, https://gitlab.com/relukko/pyrelukko/-/issues
|
|
17
20
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pyrelukko/__init__.py,sha256=n-mTJV7AOfr4bljtDxok3E3gXIBRk-kFa2_Ql3S8Ht0,61
|
|
2
|
+
pyrelukko/pyrelukko.py,sha256=8ea0t-qoQqoP7K1BZ6iaDk2ZSsBxuY3J_Z24P8PdJdY,12335
|
|
3
|
+
pyrelukko/retry.py,sha256=XeCc0trPhAggdEnu2nwtpFderlHaDQFTXH_O1dLeiGQ,1587
|
|
4
|
+
pyrelukko/testcontainers.py,sha256=mSUfnyBFVmt9N9LoI_EwXG4EomY8pQCvHzff2ESio-8,3354
|
|
5
|
+
pyrelukko/version.py,sha256=6G7fdnvpmeN8CdaYpJw3Od9s7r0YgcIf5M2MnU2YwDs,44
|
|
6
|
+
pyrelukko-0.5.0.dist-info/LICENSE,sha256=aEI4dThWmRUiEPch0-KaZQmHZgTyuz88Edmp25H6tAw,1089
|
|
7
|
+
pyrelukko-0.5.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
|
8
|
+
pyrelukko-0.5.0.dist-info/METADATA,sha256=OhhPL2dubn9jQuSXoa57FTkf3-YkZPuXHvNEJn15aqw,887
|
|
9
|
+
pyrelukko-0.5.0.dist-info/RECORD,,
|
pyrelukko-0.3.0.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
pyrelukko/__init__.py,sha256=n-mTJV7AOfr4bljtDxok3E3gXIBRk-kFa2_Ql3S8Ht0,61
|
|
2
|
-
pyrelukko/pyrelukko.py,sha256=bQDyQOWtsUznSXwdXRLg6Pg6EFomTgRzhlX4jOzHqdI,11438
|
|
3
|
-
pyrelukko/retry.py,sha256=XeCc0trPhAggdEnu2nwtpFderlHaDQFTXH_O1dLeiGQ,1587
|
|
4
|
-
pyrelukko/testcontainers.py,sha256=sJluMF9ImcQDGTB0w6s4ySCzOY5S9OKTpWQ8XQp05Y8,3555
|
|
5
|
-
pyrelukko/version.py,sha256=NnZOmpocvSUCHLODp9u2VznENpXTvQOdCMjMjqqNyf0,44
|
|
6
|
-
pyrelukko-0.3.0.dist-info/LICENSE,sha256=aEI4dThWmRUiEPch0-KaZQmHZgTyuz88Edmp25H6tAw,1089
|
|
7
|
-
pyrelukko-0.3.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
|
8
|
-
pyrelukko-0.3.0.dist-info/METADATA,sha256=C8SUSQrskczP10ooDzTUYW22z4sS4g1fv2uUlnWsb3k,735
|
|
9
|
-
pyrelukko-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|