Skip to content

Commit

Permalink
casync: reuse requests session in RemoteChunkReader (#25045)
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm authored Jul 6, 2022
1 parent 59c2861 commit 50434d6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion system/hardware/tici/casync.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ class RemoteChunkReader(ChunkReader):
def __init__(self, url: str) -> None:
super().__init__()
self.url = url
self.session = requests.Session()

def read(self, chunk: Chunk) -> bytes:
sha_hex = chunk.sha.hex()
url = os.path.join(self.url, sha_hex[:4], sha_hex + ".cacnk")

for i in range(CHUNK_DOWNLOAD_RETRIES):
try:
resp = requests.get(url, timeout=CHUNK_DOWNLOAD_TIMEOUT)
resp = self.session.get(url, timeout=CHUNK_DOWNLOAD_TIMEOUT)
break
except Exception:
if i == CHUNK_DOWNLOAD_RETRIES - 1:
Expand Down

0 comments on commit 50434d6

Please sign in to comment.