fix(work): show client idle timeout as red result-unknown card
This commit is contained in:
@@ -10,10 +10,13 @@ DELIVERY={None:'尚未接收结果','ready':'已接收结果,等待投递','se
|
||||
'replied':'结果已发送到当前会话','unknown':'结果投递待核对','discarded':'结果已停止交付'}
|
||||
|
||||
|
||||
def card_content(task_id,execution,delivery,files=None):
|
||||
def card_content(task_id,execution,delivery,files=None,connection_lost=False):
|
||||
execution=execution if execution in EXECUTION else 'unknown'
|
||||
color='green' if execution=='completed' else 'red' if execution in {'failed','interrupted'} else 'orange' if execution in {'waiting_for_approval','unknown'} else 'blue'
|
||||
elements=[{'tag':'div','text':{'tag':'plain_text','content':'任务状态:'+EXECUTION[execution]}},
|
||||
label=EXECUTION[execution]
|
||||
if connection_lost and execution not in {'completed','failed','cancelled','interrupted'}:
|
||||
color='red';label='客户端失联,任务结果待核对'
|
||||
elements=[{'tag':'div','text':{'tag':'plain_text','content':'任务状态:'+label}},
|
||||
{'tag':'div','text':{'tag':'plain_text','content':'文字回复:'+DELIVERY.get(delivery,'状态待核对')}},
|
||||
{'tag':'note','elements':[{'tag':'plain_text','content':'任务编号:'+task_id}]}]
|
||||
if files is not None:
|
||||
@@ -38,10 +41,19 @@ class TaskCards:
|
||||
self.state,self.db,self.platform,self.worker_id,self.clock=state,state.db,platform,worker_id,clock
|
||||
self.files_enabled=files_enabled
|
||||
with self.db:
|
||||
self.db.execute('''CREATE TABLE IF NOT EXISTS work_task_connection_v3(
|
||||
task_id TEXT PRIMARY KEY,reason TEXT NOT NULL)''')
|
||||
self.db.execute('''CREATE TABLE IF NOT EXISTS work_task_cards_v3(
|
||||
task_id TEXT PRIMARY KEY,message_id TEXT NOT NULL,digest TEXT NOT NULL,
|
||||
status TEXT NOT NULL,worker_id TEXT NOT NULL,updated_at DOUBLE PRECISION NOT NULL)''')
|
||||
|
||||
def mark_connection_lost(self,task_id):
|
||||
with self.db:
|
||||
self.db.execute("INSERT INTO work_task_connection_v3 VALUES(?,'client_idle_timeout') ON CONFLICT DO NOTHING",(task_id,))
|
||||
|
||||
def clear_connection_lost(self,task_id):
|
||||
with self.db:self.db.execute('DELETE FROM work_task_connection_v3 WHERE task_id=?',(task_id,))
|
||||
|
||||
def valid(self,task):
|
||||
device=self.state.store.device(task['host_id']) if task else None
|
||||
return bool(device and not device['revoked'] and device['owner']==task['owner']
|
||||
@@ -57,7 +69,8 @@ class TaskCards:
|
||||
if self.files_enabled:
|
||||
files=[r['status']for r in self.db.execute("SELECT status FROM work_files_v1 WHERE task_id=? AND environment=? AND app_id=? AND direction='output'",
|
||||
(task['turn_id'],self.state.environment,self.state.app_id)).fetchall()]
|
||||
return card_content(task['turn_id'],execution,delivery['status'] if delivery else None,files)
|
||||
lost=self.db.execute('SELECT reason FROM work_task_connection_v3 WHERE task_id=?',(task['turn_id'],)).fetchone()
|
||||
return card_content(task['turn_id'],execution,delivery['status'] if delivery else None,files,connection_lost=bool(lost))
|
||||
|
||||
async def flush(self):
|
||||
# Bound one maintenance pass; business result delivery remains independent.
|
||||
|
||||
Reference in New Issue
Block a user