pyrelukko 0.5.0__py3-none-any.whl → 0.6.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 CHANGED
@@ -39,6 +39,8 @@ RETRY_KWARGS = [
39
39
  OWN_KWARGS = [
40
40
  'acquire_wait_for_timeout',
41
41
  'acquire_modulo',
42
+ 'disable_websocket',
43
+ 'raise_when_acquire_fails',
42
44
  'ws_ping_interval',
43
45
  'ws_ping_timeout',
44
46
  'ws_wait_for_timeout',
@@ -75,11 +77,13 @@ class RelukkoClient:
75
77
  )
76
78
  self._setup_session(api_key, **kwargs)
77
79
  self._setup_http_adapters_retry(**kwargs)
78
- self.ws_wait_for_timeout = 2
80
+ self.acquire_modulo = 100
81
+ self.acquire_wait_for_timeout = 2
82
+ self.disable_websocket = False
83
+ self.raise_when_acquire_fails = True
79
84
  self.ws_ping_interval = 60
80
85
  self.ws_ping_timeout = 20
81
- self.acquire_wait_for_timeout = 2
82
- self.acquire_modulo = 100
86
+ self.ws_wait_for_timeout = 2
83
87
  self._setup_pyrelukko_kwargs(**kwargs)
84
88
 
85
89
  self.base_url = self._setup_base_url(base_url)
@@ -224,22 +228,29 @@ class RelukkoClient:
224
228
  if elapsed_time > max_run_time:
225
229
  self.ws_running.clear()
226
230
  _thread_store.insert(0, None)
227
- return
231
+ break
228
232
  # If self.message_recieved is True try to get lock ASAP!
229
233
  # Otherwise only in every Xth run in case websocket broke.
230
234
  if got_message or loop_counter % self.acquire_modulo == 0:
231
- res = self._make_request(
232
- url=url, method="POST", payload=payload)
235
+ try:
236
+ res = self._make_request(
237
+ url=url, method="POST", payload=payload)
238
+ except (
239
+ *self.exceptions, RuntimeError, requests.HTTPError) as e:
240
+ logger.warning("Last exception was: %s!\nGiving up!", e)
241
+ _thread_store.insert(0, e)
242
+ break
233
243
  loop_counter += 1
234
244
  if res is None:
235
245
  # Conflict 409
236
246
  got_message = self.message_received.wait(
237
247
  timeout=self.acquire_wait_for_timeout)
238
248
  self.message_received.clear()
239
- else:
240
- _thread_store.insert(0, res)
241
- self.ws_running.clear()
242
- return
249
+ continue
250
+
251
+ _thread_store.insert(0, res)
252
+ self.ws_running.clear()
253
+ break
243
254
 
244
255
  def _check_response(self, response: requests.Response):
245
256
  match response.status_code:
@@ -247,20 +258,27 @@ class RelukkoClient:
247
258
  return response.json()
248
259
  case 400 | 403:
249
260
  err = response.json()
250
- logger.warning(err.get('status'), err.get('message'))
261
+ logger.warning("4xx HTTP Error [%d](%s) - %s:%s",
262
+ response.status_code, response.reason,
263
+ str(err.get('status')), err.get('message'))
251
264
  response.raise_for_status()
252
265
  case 409:
253
266
  err = response.json()
254
- logger.info(err.get('status'), err.get('message'))
267
+ logger.warning("409 HTTP Error [%d](%s) - %s:%s",
268
+ response.status_code, response.reason,
269
+ str(err.get('status')), err.get('message'))
255
270
  return None
256
271
  case 500 | 502 | 503 | 504:
257
272
  logger.warning("[%d](%s) %s",
258
273
  response.status_code, response.reason, response.text)
259
- raise RelukkoDoRetry()
274
+ raise RelukkoDoRetry(
275
+ f"5xx HTTP Error: [{response.status_code}]"
276
+ f"({response.reason})")
260
277
  case _:
261
278
  logger.warning("[%d](%s) %s",
262
279
  response.status_code, response.reason, response.text)
263
- raise RuntimeError()
280
+ raise RuntimeError(
281
+ f"Give up: [{response.status_code}]({response.reason})")
264
282
 
265
283
  def _make_request(
266
284
  self,
@@ -293,10 +311,11 @@ class RelukkoClient:
293
311
 
294
312
  url = f"{self.base_url}/v1/locks/"
295
313
 
296
- self.ws_running.set()
297
- self.ws_listener = threading.Thread(
298
- target=asyncio.run, args=(self._websocket_listener(),))
299
- self.ws_listener.start()
314
+ if not self.disable_websocket:
315
+ self.ws_running.set()
316
+ self.ws_listener = threading.Thread(
317
+ target=asyncio.run, args=(self._websocket_listener(),))
318
+ self.ws_listener.start()
300
319
 
301
320
  thread_store = []
302
321
  http_thread = threading.Thread(
@@ -304,9 +323,18 @@ class RelukkoClient:
304
323
  args=(url, max_run_time, payload, thread_store))
305
324
  http_thread.start()
306
325
  http_thread.join()
307
- self.ws_listener.join()
308
326
 
309
- return thread_store[0]
327
+ if not self.disable_websocket:
328
+ self.ws_listener.join()
329
+
330
+ if thread_store:
331
+ if (
332
+ self.raise_when_acquire_fails
333
+ and isinstance(thread_store[0], Exception)
334
+ ):
335
+ raise thread_store[0]
336
+ return thread_store[0]
337
+ return None
310
338
 
311
339
  def get_lock(self, lock_id: str) -> Dict:
312
340
  """
pyrelukko/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  # pylint: disable=all
2
- __version__ = "0.5.0"
2
+ __version__ = "0.6.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pyrelukko
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Relukko client.
5
5
  Author-email: Reto Zingg <g.d0b3rm4n@gmail.com>
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,9 @@
1
+ pyrelukko/__init__.py,sha256=n-mTJV7AOfr4bljtDxok3E3gXIBRk-kFa2_Ql3S8Ht0,61
2
+ pyrelukko/pyrelukko.py,sha256=Pjn2pf4rg1rDgAHzUSFdLnooHttn0ZLh3g_29Fxi0RM,13499
3
+ pyrelukko/retry.py,sha256=XeCc0trPhAggdEnu2nwtpFderlHaDQFTXH_O1dLeiGQ,1587
4
+ pyrelukko/testcontainers.py,sha256=mSUfnyBFVmt9N9LoI_EwXG4EomY8pQCvHzff2ESio-8,3354
5
+ pyrelukko/version.py,sha256=q0h0LBikcev1aArInPZOcWowTR0WPbUbXJg_OX6XtkU,44
6
+ pyrelukko-0.6.0.dist-info/LICENSE,sha256=aEI4dThWmRUiEPch0-KaZQmHZgTyuz88Edmp25H6tAw,1089
7
+ pyrelukko-0.6.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
8
+ pyrelukko-0.6.0.dist-info/METADATA,sha256=DwCYVR3ps9F4ej1xrgd1DrYcvmZJR7liQ0nxjZfUf4w,887
9
+ pyrelukko-0.6.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
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,,