File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ inquirer >=2.10.0, <=3.1.3
1313psutil <5.9.5
1414click <=8.1.3
1515python-multipart>=0.0.5, <=0.0.6
16+ backoff >=2.2.1, <2.3.0
1617
1718fastapi >=0.92.0, <0.100.0
1819starlette # https://fastapi.tiangolo.com/deployment/versions/#about-starlette
Original file line number Diff line number Diff line change 2323from typing import Any , Optional , Tuple
2424from urllib .parse import urljoin
2525
26+ import backoff
2627import requests
2728from requests .exceptions import ConnectionError , ConnectTimeout , ReadTimeout
2829
@@ -431,6 +432,7 @@ def _get(self) -> Any:
431432 # we consider the queue is empty to avoid failing the app.
432433 raise queue .Empty
433434
435+ @backoff .on_exception (backoff .expo , (RuntimeError , requests .exceptions .HTTPError ))
434436 def put (self , item : Any ) -> None :
435437 if not self .app_id :
436438 raise ValueError (f"The Lightning App ID couldn't be extracted from the queue name: { self .name } " )
Original file line number Diff line number Diff line change @@ -217,13 +217,21 @@ def test_http_queue_get(self, monkeypatch):
217217
218218def test_unreachable_queue (monkeypatch ):
219219 monkeypatch .setattr (queues , "HTTP_QUEUE_TOKEN" , "test-token" )
220+
220221 test_queue = QueuingSystem .HTTP .get_queue (queue_name = "test_http_queue" )
221222
222- resp = mock .MagicMock ()
223- resp .status_code = 204
223+ resp1 = mock .MagicMock ()
224+ resp1 .status_code = 204
225+
226+ resp2 = mock .MagicMock ()
227+ resp2 .status_code = 201
224228
225229 test_queue .client = mock .MagicMock ()
226- test_queue .client .post . return_value = resp
230+ test_queue .client .post = mock . Mock ( side_effect = [ resp1 , resp1 , resp2 ])
227231
228232 with pytest .raises (queue .Empty ):
229233 test_queue ._get ()
234+
235+ # Test backoff on queue.put
236+ test_queue .put ("foo" )
237+ assert test_queue .client .post .call_count == 3
You can’t perform that action at this time.
0 commit comments