Switch failable to use outcome

guilles_counter_review
Guillermo Rodriguez 2025-02-03 16:02:38 -03:00
parent eee19f1953
commit 36cb7b758a
No known key found for this signature in database
GPG Key ID: 002CC5F1E6BDA53E
3 changed files with 21 additions and 18 deletions

View File

@ -19,6 +19,7 @@ dependencies = [
"zstandard>=0.23.0,<0.24", "zstandard>=0.23.0,<0.24",
"click>=8.1.8,<9", "click>=8.1.8,<9",
"httpx>=0.28.1,<0.29", "httpx>=0.28.1,<0.29",
"outcome>=1.3.0.post0",
] ]
[project.scripts] [project.scripts]

View File

@ -12,6 +12,7 @@ import trio
import leap import leap
import anyio import anyio
import httpx import httpx
import outcome
from PIL import ( from PIL import (
Image, Image,
@ -36,25 +37,24 @@ from skynet.ipfs import (
REQUEST_UPDATE_TIME: int = 3 REQUEST_UPDATE_TIME: int = 3
# TODO, consider using the `outcome` lib instead? async def failable(fn: partial, ret_fail=None):
# - it's already purpose built for exactly this, boxing (async) o = await outcome.acapture(fn)
# function invocations.. match o:
# |_ https://outcome.readthedocs.io/en/latest/api.html#outcome.capture case outcome.Error(error=(
async def failable( OSError() |
fn: partial, json.JSONDecodeError() |
ret_fail=None, anyio.BrokenResourceError() |
): httpx.ConnectError() |
try: httpx.ConnectTimeout() |
return await fn() httpx.ReadError() |
except ( httpx.ReadTimeout() |
OSError, leap.errors.TransactionPushError()
json.JSONDecodeError, )):
anyio.BrokenResourceError,
httpx.ReadError,
leap.errors.TransactionPushError
):
return ret_fail return ret_fail
case _:
return o.unwrap()
# TODO, again the prefix XD # TODO, again the prefix XD
# -[ ] better name then `GPUConnector` ?? # -[ ] better name then `GPUConnector` ??

View File

@ -2232,6 +2232,7 @@ dependencies = [
{ name = "httpx" }, { name = "httpx" },
{ name = "msgspec" }, { name = "msgspec" },
{ name = "numpy" }, { name = "numpy" },
{ name = "outcome" },
{ name = "pillow" }, { name = "pillow" },
{ name = "protobuf" }, { name = "protobuf" },
{ name = "py-leap" }, { name = "py-leap" },
@ -2282,6 +2283,7 @@ requires-dist = [
{ name = "httpx", specifier = ">=0.28.1,<0.29" }, { name = "httpx", specifier = ">=0.28.1,<0.29" },
{ name = "msgspec", specifier = ">=0.19.0,<0.20" }, { name = "msgspec", specifier = ">=0.19.0,<0.20" },
{ name = "numpy", specifier = "<2.1" }, { name = "numpy", specifier = "<2.1" },
{ name = "outcome", specifier = ">=1.3.0.post0" },
{ name = "pillow", specifier = ">=10.0.1,<11" }, { name = "pillow", specifier = ">=10.0.1,<11" },
{ name = "protobuf", specifier = ">=5.29.3,<6" }, { name = "protobuf", specifier = ">=5.29.3,<6" },
{ name = "py-leap", git = "https://github.com/guilledk/py-leap.git?rev=v0.1a32" }, { name = "py-leap", git = "https://github.com/guilledk/py-leap.git?rev=v0.1a32" },