From 089e57005405309a0acd787fba9bacc3b49418f4 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 10 Nov 2023 00:51:12 +0100 Subject: [PATCH] packages/reflex-cache: don't 502 if pinning to ipfs cluster fails --- packages/servers/reflex-cache/reflex_cache/ipfs.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/servers/reflex-cache/reflex_cache/ipfs.py b/packages/servers/reflex-cache/reflex_cache/ipfs.py index de71b1c..15c8c52 100644 --- a/packages/servers/reflex-cache/reflex_cache/ipfs.py +++ b/packages/servers/reflex-cache/reflex_cache/ipfs.py @@ -32,11 +32,14 @@ class IPFSController: print(f"Mapped: {nar} -> /ipfs/{hash}") self.__db.set_path(nar, hash) expireAt = datetime.now(timezone.utc) + timedelta(hours=24) - rClusterPin = requests_unixsocket.post( - f"{self.__clusterAddr}/pins/ipfs/{hash}?expire-at={quote_plus(expireAt.isoformat())}&mode=recursive&name=reflex-{quote_plus(nar)}&replication-max=2&replication-min=1", files=upload - ) - if rClusterPin.status_code != 200: - print(f"Warning: failed to pin {hash} on IPFS cluster") + try: + rClusterPin = requests_unixsocket.post( + f"{self.__clusterAddr}/pins/ipfs/{hash}?expire-at={quote_plus(expireAt.isoformat())}&mode=recursive&name=reflex-{quote_plus(nar)}&replication-max=2&replication-min=1", files=upload + ) + if rClusterPin.status_code != 200: + print(f"Warning: failed to pin {hash} on IPFS cluster: {rClusterPin.status_code}") + except requests.ConnectionError as e: + print(f"Warning: failed to pin {hash} on IPFS cluster: {e}") callback() return (nar, 200, hash) except requests.ConnectionError as e: