feat(collect): choose product status scope

This commit is contained in:
chengma
2026-07-18 16:46:59 +08:00
parent 0cf23db403
commit 4658a1ca61
11 changed files with 420 additions and 41 deletions
+56 -8
View File
@@ -20,6 +20,7 @@ from .. import (
image_studio_export,
image_studio_generation,
image_studio_images,
product_status,
)
from ..collect_skip import ALIAS_UNMATCHED, LOGIN_REQUIRED, empty_skip_reason_counts
from .widgets import *
@@ -1878,6 +1879,7 @@ class CollectWorker(BaseWorker):
config=None,
preflight=True,
diagnostic_log_dir=None,
collect_scope="all",
):
super().__init__()
self.tasks = list(tasks)
@@ -1885,6 +1887,7 @@ class CollectWorker(BaseWorker):
self.config = config
self.preflight = preflight
self.diagnostic_log_dir = diagnostic_log_dir
self.collect_scope = product_status.normalize_collect_scope(collect_scope)
self._run_id = None
def execute(self):
@@ -1908,6 +1911,10 @@ class CollectWorker(BaseWorker):
login_required_accounts = {}
preflight_info = {}
skip_reason_counts = empty_skip_reason_counts()
product_status_counts = {
status: 0 for status in product_status.VALID_PRODUCT_STATUSES
}
status_scope_skipped = 0
self._run_id = self._create_run_log(eligible, batch_ids)
self._emit_activity(
@@ -1935,6 +1942,9 @@ class CollectWorker(BaseWorker):
extra={
**blocked,
"skip_reason_counts": dict(skip_reason_counts),
"collect_scope": self.collect_scope,
"product_status_counts": dict(product_status_counts),
"status_scope_skipped": status_scope_skipped,
},
)
self._finish_run_log("blocked", summary)
@@ -2111,9 +2121,22 @@ class CollectWorker(BaseWorker):
{
"item_id": task.item_id,
"old_cover_path": self._old_cover_path(account, task),
"collection_scope": self.collect_scope,
},
on_step=on_step,
)
detected_status = product_status.normalize_status(
result.get("product_status")
)
product_status_counts[detected_status] += 1
if result.get("product_status_error"):
self._write_diagnostic_log(
"商品状态检测失败,已按状态未知保存",
level="WARNING",
step="read_product_status",
task=task,
payload={"error": result.get("product_status_error")},
)
if result.get("close_target_confirmed") is False:
self._log_run_event(
"step=close_product result=uncertain detail=任务 {task_id} 商品 {item_id} 商品页已请求关闭,但未在短时间内确认关闭;采集结果已保留,继续处理后续任务".format(
@@ -2133,6 +2156,35 @@ class CollectWorker(BaseWorker):
"close_target_confirmed": False,
},
)
if result.get("collection_skipped"):
activity_result = "skipped"
current_step = "read_product_status"
reason = result.get("collection_skip_reason") or product_status.collect_skip_reason(
detected_status
)
db.set_product_status(
task.id,
detected_status,
result.get("product_status_note"),
path=self.db_path,
)
db.mark_skipped(task.id, reason, path=self.db_path)
skipped += 1
status_scope_skipped += 1
self.row_updated.emit(
task.id,
{"status": "skipped", "last_error": reason},
)
self._log_run_event(
"step=read_product_status result=skipped detail=任务 {task_id} 商品 {item_id} {reason}".format(
task_id=task.id,
item_id=task.item_id,
reason=reason,
),
task=task,
level="warning",
)
continue
current_step = "db_write"
self._emit_activity(
"task_step",
@@ -2156,14 +2208,6 @@ class CollectWorker(BaseWorker):
product_status_note=result.get("product_status_note"),
path=self.db_path,
)
if result.get("product_status_error"):
self._write_diagnostic_log(
"商品状态检测失败,已按状态未知保存",
level="WARNING",
step="read_product_status",
task=task,
payload={"error": result.get("product_status_error")},
)
collected += 1
elapsed_ms = self._elapsed_ms(started)
self.row_updated.emit(
@@ -2235,6 +2279,9 @@ class CollectWorker(BaseWorker):
**preflight_info,
"login_required_accounts": list(login_required_accounts.values()),
"skip_reason_counts": dict(skip_reason_counts),
"collect_scope": self.collect_scope,
"product_status_counts": dict(product_status_counts),
"status_scope_skipped": status_scope_skipped,
},
)
self._finish_run_log("cancelled" if self.should_cancel() else "done", summary)
@@ -2540,6 +2587,7 @@ class CollectWorker(BaseWorker):
options={
"batch_ids": batch_ids,
"preflight": self.preflight,
"collect_scope": self.collect_scope,
},
path=self.db_path,
)