mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
Async!
This commit is contained in:
parent
b65bc9dca7
commit
7ae8b50d14
@ -1019,11 +1019,12 @@ class NativeStorageServer(service.MultiService):
|
|||||||
self._reconnector.reset()
|
self._reconnector.reset()
|
||||||
|
|
||||||
|
|
||||||
def _pick_a_http_server(
|
@async_to_deferred
|
||||||
|
async def _pick_a_http_server(
|
||||||
reactor,
|
reactor,
|
||||||
nurls: list[DecodedURL],
|
nurls: list[DecodedURL],
|
||||||
request: Callable[[Any, DecodedURL], defer.Deferred[Any]]
|
request: Callable[[Any, DecodedURL], defer.Deferred[Any]]
|
||||||
) -> defer.Deferred[Optional[DecodedURL]]:
|
) -> Optional[DecodedURL]:
|
||||||
"""Pick the first server we successfully send a request to.
|
"""Pick the first server we successfully send a request to.
|
||||||
|
|
||||||
Fires with ``None`` if no server was found, or with the ``DecodedURL`` of
|
Fires with ``None`` if no server was found, or with the ``DecodedURL`` of
|
||||||
@ -1034,22 +1035,19 @@ def _pick_a_http_server(
|
|||||||
for nurl in nurls
|
for nurl in nurls
|
||||||
])
|
])
|
||||||
|
|
||||||
def failed(failure: Failure):
|
try:
|
||||||
|
_, nurl = await queries
|
||||||
|
return nurl
|
||||||
|
except Exception as e:
|
||||||
# Logging errors breaks a bunch of tests, and it's not a _bug_ to
|
# Logging errors breaks a bunch of tests, and it's not a _bug_ to
|
||||||
# have a failed connection, it's often expected and transient. More
|
# have a failed connection, it's often expected and transient. More
|
||||||
# of a warning, really?
|
# of a warning, really?
|
||||||
log.msg(
|
log.msg(
|
||||||
"Failed to connect to a storage server advertised by NURL: {}".format(
|
"Failed to connect to a storage server advertised by NURL: {}".format(
|
||||||
failure)
|
e)
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def succeeded(result: tuple[int, DecodedURL]):
|
|
||||||
_, nurl = result
|
|
||||||
return nurl
|
|
||||||
|
|
||||||
return queries.addCallbacks(succeeded, failed)
|
|
||||||
|
|
||||||
|
|
||||||
@implementer(IServer)
|
@implementer(IServer)
|
||||||
class HTTPNativeStorageServer(service.MultiService):
|
class HTTPNativeStorageServer(service.MultiService):
|
||||||
|
Loading…
Reference in New Issue
Block a user