feat(work): recover text and attachment delivery independently
This commit is contained in:
@@ -7,10 +7,12 @@ import time
|
||||
EXECUTION={'queued':'排队中','running':'执行中','waiting_for_approval':'等待本人确认',
|
||||
'completed':'执行完成','failed':'执行失败','cancelled':'已取消','interrupted':'已中断','unknown':'状态待核对'}
|
||||
DELIVERY={None:'尚未接收结果','ready':'已接收结果,等待投递','sending':'正在投递结果',
|
||||
'replied':'结果已发送到当前会话','unknown':'结果投递待核对','discarded':'结果已停止交付'}
|
||||
'replied':'结果已发送到当前会话','unknown':'结果投递待核对','discarded':'结果已停止交付',
|
||||
'failed':'结果未能投递'}
|
||||
|
||||
|
||||
def card_content(task_id,execution,delivery,files=None,connection_lost=False,remote_approvals=False):
|
||||
def card_content(task_id,execution,delivery,files=None,connection_lost=False,remote_approvals=False,
|
||||
attachment_exception=None):
|
||||
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'
|
||||
if execution=='cancelled':color='grey'
|
||||
@@ -26,6 +28,8 @@ def card_content(task_id,execution,delivery,files=None,connection_lost=False,rem
|
||||
elements.insert(1,{'tag':'div','text':{'tag':'plain_text','content':hint}})
|
||||
if execution=='completed' and delivery!='replied':
|
||||
elements.insert(1,{'tag':'div','text':{'tag':'plain_text','content':'任务已执行完成,结果交付请看下方状态。'}})
|
||||
if attachment_exception:
|
||||
elements.insert(-1,{'tag':'div','text':{'tag':'plain_text','content':attachment_exception}})
|
||||
return {'config':{'wide_screen_mode':True,'enable_forward':False},
|
||||
'header':{'template':color,'title':{'tag':'plain_text','content':'海诺任务进度'}},'elements':elements}
|
||||
|
||||
@@ -34,6 +38,7 @@ class TaskCards:
|
||||
def __init__(self,state,platform,worker_id,clock=time.time,files_enabled=False,remote_approvals=False):
|
||||
self.state,self.db,self.platform,self.worker_id,self.clock=state,state.db,platform,worker_id,clock
|
||||
self.files_enabled=files_enabled
|
||||
self.file_receipts=None
|
||||
self.remote_approvals=remote_approvals
|
||||
with self.db:
|
||||
self.db.execute('''CREATE TABLE IF NOT EXISTS work_task_connection_v3(
|
||||
@@ -61,8 +66,16 @@ class TaskCards:
|
||||
if task['status']=='unknown' and execution not in {'completed','failed','cancelled','interrupted'}:execution='unknown'
|
||||
if task['deadline']<=self.clock() and execution not in {'completed','failed','cancelled','interrupted'}:execution='unknown'
|
||||
lost=self.db.execute('SELECT reason FROM work_task_connection_v3 WHERE task_id=?',(task['turn_id'],)).fetchone()
|
||||
exceptions=[]
|
||||
if self.file_receipts:
|
||||
receipts=self.file_receipts(task)
|
||||
unknown=sum(r['status']=='unknown' for r in receipts)
|
||||
failed=sum(r['status'] in {'failed','expired','discarded'} for r in receipts)
|
||||
if unknown:exceptions.append(f'{unknown} 份附件的送达结果待核对。')
|
||||
if failed:exceptions.append(f'{failed} 份附件未能交付。')
|
||||
return card_content(task['turn_id'],execution,delivery['status'] if delivery else None,
|
||||
connection_lost=bool(lost),remote_approvals=self.remote_approvals)
|
||||
connection_lost=bool(lost),remote_approvals=self.remote_approvals,
|
||||
attachment_exception=''.join(exceptions))
|
||||
|
||||
async def flush(self):
|
||||
# Bound one maintenance pass; business result delivery remains independent.
|
||||
|
||||
Reference in New Issue
Block a user