fix(work): show client idle timeout as red result-unknown card
This commit is contained in:
@@ -58,6 +58,10 @@ class Pending:
|
||||
progress: asyncio.Event = field(default_factory=asyncio.Event)
|
||||
|
||||
|
||||
class ClientIdleTimeout(asyncio.TimeoutError):
|
||||
"""No authenticated task progress arrived within the idle timeout."""
|
||||
|
||||
|
||||
class Broker:
|
||||
def __init__(self, settings, redis, store):
|
||||
self.s, self.r, self.store = settings, redis, store
|
||||
@@ -66,6 +70,7 @@ class Broker:
|
||||
self.worker_id = uuid.uuid4().hex
|
||||
self.lifecycle = None
|
||||
self.files = None
|
||||
self.task_cards = None
|
||||
|
||||
async def replies(self, pub):
|
||||
async for message in pub.listen():
|
||||
@@ -113,7 +118,8 @@ class Broker:
|
||||
if item.future in done:
|
||||
return item.future.result()
|
||||
if not done:
|
||||
raise asyncio.TimeoutError()
|
||||
if remaining<=self.s.request_timeout:raise asyncio.TimeoutError()
|
||||
raise ClientIdleTimeout()
|
||||
finally:
|
||||
progress.cancel()
|
||||
with contextlib.suppress(asyncio.CancelledError):
|
||||
@@ -212,10 +218,12 @@ class Broker:
|
||||
self.lifecycle.transition(turn,"completed","finished")
|
||||
self.store.audit(owner, "instruction", host, result.get("status","unknown") if task else "completed")
|
||||
return result
|
||||
except asyncio.TimeoutError:
|
||||
except asyncio.TimeoutError as error:
|
||||
self.store.finish(turn, "unknown")
|
||||
if task:
|
||||
self.lifecycle.transition(turn,"inflight","unknown")
|
||||
if isinstance(error,ClientIdleTimeout) and self.task_cards:
|
||||
self.task_cards.mark_connection_lost(turn)
|
||||
return {"status": "unknown", "turn_id": turn,
|
||||
"result": "等待结果超时,执行状态未知;不要直接重发有副作用的任务。"}
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user