feat: 批量重跑实时刷新任务状态 (#143)
This commit is contained in:
@@ -133,6 +133,7 @@ class ClaimTaskWorker(QObject):
|
||||
retryableFailed = pyqtSignal(str)
|
||||
failed = pyqtSignal(str)
|
||||
deviceUnavailable = pyqtSignal(str)
|
||||
taskStarted = pyqtSignal(str, str, int, int)
|
||||
outcome = pyqtSignal(str, str, str)
|
||||
completed = pyqtSignal()
|
||||
shutdownCompleted = pyqtSignal()
|
||||
@@ -309,11 +310,23 @@ class ClaimTaskWorker(QObject):
|
||||
client,
|
||||
android_serial,
|
||||
cancelled=lambda: self._cancelled,
|
||||
started=lambda started_id, current=index + 1: self.taskStarted.emit(
|
||||
started_id,
|
||||
command.target_type.value,
|
||||
current,
|
||||
len(command.task_ids),
|
||||
),
|
||||
collect_service_factory=self._collect_service_factory,
|
||||
)
|
||||
result = service.execute_selected(task_id)
|
||||
else:
|
||||
result = self._execute_purchase_rerun(task_id, client, android_serial)
|
||||
result = self._execute_purchase_rerun(
|
||||
task_id,
|
||||
client,
|
||||
android_serial,
|
||||
current=index + 1,
|
||||
total=len(command.task_ids),
|
||||
)
|
||||
except (CollectRerunError, PurchaseRerunError, ValueError) as exc:
|
||||
self.outcome.emit("skipped", str(exc), task_id)
|
||||
continue
|
||||
@@ -328,7 +341,12 @@ class ClaimTaskWorker(QObject):
|
||||
break
|
||||
|
||||
def _execute_purchase_rerun(
|
||||
self, task_id: str, client: ClientInfo, android_serial: str
|
||||
self,
|
||||
task_id: str,
|
||||
client: ClientInfo,
|
||||
android_serial: str,
|
||||
current: int = 1,
|
||||
total: int = 1,
|
||||
):
|
||||
"""执行一次安全采购,并在真实下单后完成核单和 Admin 上报。"""
|
||||
|
||||
@@ -347,6 +365,12 @@ class ClaimTaskWorker(QObject):
|
||||
android_serial,
|
||||
factory,
|
||||
cancelled=lambda: self._cancelled,
|
||||
started=lambda started_id: self.taskStarted.emit(
|
||||
started_id,
|
||||
TaskType.PURCHASE.value,
|
||||
current,
|
||||
total,
|
||||
),
|
||||
)
|
||||
result = service.execute_selected(task_id)
|
||||
if result.kind != "reconcile_pending":
|
||||
@@ -976,8 +1000,8 @@ class PDDTaskPageEvent(QObject):
|
||||
self._claim_busy = True
|
||||
self._page.set_rerun_running(True)
|
||||
self._page.set_engine_status(
|
||||
f"正在检查 Android 设备并准备重新{'采集' if command.target_type is TaskType.COLLECT else '采购'}"
|
||||
f" {len(command.task_ids)} 条任务…"
|
||||
f"已加入队列 {len(command.task_ids)} 条,正在检查 Android 设备,等待开始重新"
|
||||
f"{'采集' if command.target_type is TaskType.COLLECT else '采购'}…"
|
||||
)
|
||||
self._reload()
|
||||
|
||||
@@ -1025,6 +1049,24 @@ class PDDTaskPageEvent(QObject):
|
||||
self._rerun_failed += 1
|
||||
self._page.set_engine_status(message)
|
||||
|
||||
@pyqtSlot(str, str, int, int)
|
||||
def _on_rerun_task_started(
|
||||
self,
|
||||
task_id: str,
|
||||
task_type: str,
|
||||
current: int,
|
||||
total: int,
|
||||
) -> None:
|
||||
"""数据库进入 running 后,立即让主线程刷新当前任务。"""
|
||||
|
||||
if self._closing or self._claim_operation != "rerun":
|
||||
return
|
||||
action = "采集" if task_type == TaskType.COLLECT.value else "采购"
|
||||
self._reload()
|
||||
self._page.set_engine_status(
|
||||
f"批量重新{action}:正在{action} {task_id}({current}/{total})"
|
||||
)
|
||||
|
||||
@pyqtSlot(str)
|
||||
def _on_rerun_failed(self, message: str) -> None:
|
||||
if self._closing:
|
||||
@@ -1203,6 +1245,7 @@ class PDDTaskPageEvent(QObject):
|
||||
worker.retryableFailed.connect(self._route_claim_retryable_failed)
|
||||
worker.failed.connect(self._route_claim_failed)
|
||||
worker.deviceUnavailable.connect(self._route_device_unavailable)
|
||||
worker.taskStarted.connect(self._on_rerun_task_started)
|
||||
worker.outcome.connect(self._route_claim_outcome)
|
||||
worker.completed.connect(self._on_claim_cycle_completed)
|
||||
# QThread 对象属于主线程;显式直连可在 shutdown_worker 完成释放后
|
||||
@@ -1704,6 +1747,10 @@ class PDDTaskPageEvent(QObject):
|
||||
def summary_to_row(summary: TaskSummary) -> TaskRow:
|
||||
"""把领域摘要转换成只供表格显示的轻量行。"""
|
||||
|
||||
status_text = TASK_STATUS_TEXT[summary.status]
|
||||
if summary.status is TaskStatus.RUNNING:
|
||||
status_text = "采集中" if summary.task_type is TaskType.COLLECT else "采购中"
|
||||
|
||||
return TaskRow(
|
||||
remote_task_id=summary.remote_task_id,
|
||||
task_type=TASK_TYPE_TEXT[summary.task_type],
|
||||
@@ -1714,7 +1761,7 @@ def summary_to_row(summary: TaskSummary) -> TaskRow:
|
||||
size=summary.target_size or "",
|
||||
price_cents=summary.price_cent,
|
||||
quantity=summary.quantity,
|
||||
status=TASK_STATUS_TEXT[summary.status],
|
||||
status=status_text,
|
||||
latest_run_status=(
|
||||
summary.latest_run_status.value if summary.latest_run_status else ""
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user