feat(apply): block abnormal product statuses
This commit is contained in:
+23
-1
@@ -1251,6 +1251,10 @@ class ApplyWorker(BaseWorker):
|
||||
max_parallel_accounts=1,
|
||||
batch_size=None,
|
||||
diagnostic_log_dir=None,
|
||||
product_status_counts=None,
|
||||
status_scope_excluded=0,
|
||||
content_scope_excluded=0,
|
||||
apply_plan_fingerprint=None,
|
||||
):
|
||||
super().__init__()
|
||||
self.tasks = list(tasks)
|
||||
@@ -1271,6 +1275,13 @@ class ApplyWorker(BaseWorker):
|
||||
self._batch_count = 0
|
||||
self._progress_lock = threading.Lock()
|
||||
self.diagnostic_log_dir = diagnostic_log_dir
|
||||
self.product_status_counts = {
|
||||
status: int((product_status_counts or {}).get(status, 0) or 0)
|
||||
for status in product_status.VALID_PRODUCT_STATUSES
|
||||
}
|
||||
self.status_scope_excluded = max(0, int(status_scope_excluded or 0))
|
||||
self.content_scope_excluded = max(0, int(content_scope_excluded or 0))
|
||||
self.apply_plan_fingerprint = str(apply_plan_fingerprint or "") or None
|
||||
self._run_id = None
|
||||
|
||||
def execute(self):
|
||||
@@ -1295,7 +1306,7 @@ class ApplyWorker(BaseWorker):
|
||||
}
|
||||
self._run_id = self._create_run_log(eligible, batch_ids)
|
||||
self._log_run_event(
|
||||
"step=start result=start detail=运行开始:{mode},更新内容{update_mode},任务{total},每批最多{batch_size},批次{batch_count},{parallel}".format(
|
||||
"step=start result=start detail=运行开始:{mode},更新内容{update_mode},任务{total},每批最多{batch_size},批次{batch_count},{parallel};商品状态异常排除{status_excluded}条;内容缺失排除{content_excluded}条".format(
|
||||
mode="检查本轮更新" if self.dry_run else "真实更新",
|
||||
update_mode=_update_mode_label(self.update_mode),
|
||||
total=total,
|
||||
@@ -1306,6 +1317,8 @@ class ApplyWorker(BaseWorker):
|
||||
if self.max_parallel_accounts > 1
|
||||
else "串行"
|
||||
),
|
||||
status_excluded=self.status_scope_excluded,
|
||||
content_excluded=self.content_scope_excluded,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1363,6 +1376,7 @@ class ApplyWorker(BaseWorker):
|
||||
return (
|
||||
getattr(task, "stage", None) == "generated"
|
||||
and getattr(task, "status", None) in {"success", "pending", "failed"}
|
||||
and product_status.is_normal(getattr(task, "product_status", None))
|
||||
and (
|
||||
(
|
||||
appconfig.update_mode_includes_title(self.update_mode)
|
||||
@@ -1766,6 +1780,10 @@ class ApplyWorker(BaseWorker):
|
||||
"batch_count": self._batch_count,
|
||||
"update_mode": self.update_mode,
|
||||
"run_id": self._run_id,
|
||||
"product_status_counts": dict(self.product_status_counts),
|
||||
"status_scope_excluded": self.status_scope_excluded,
|
||||
"content_scope_excluded": self.content_scope_excluded,
|
||||
"apply_plan_fingerprint": self.apply_plan_fingerprint,
|
||||
}
|
||||
if blocked:
|
||||
summary["blocked"] = True
|
||||
@@ -1787,6 +1805,10 @@ class ApplyWorker(BaseWorker):
|
||||
"batch_size": self._current_batch_size,
|
||||
"batch_count": self._batch_count,
|
||||
"update_mode": self.update_mode,
|
||||
"product_status_counts": dict(self.product_status_counts),
|
||||
"status_scope_excluded": self.status_scope_excluded,
|
||||
"content_scope_excluded": self.content_scope_excluded,
|
||||
"apply_plan_fingerprint": self.apply_plan_fingerprint,
|
||||
},
|
||||
path=self.db_path,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user