fix(product-suite): finalize and cancel generation
Tests / Python 3.11 / Windows (push) Has been cancelled

This commit is contained in:
chengma
2026-07-16 17:12:41 +08:00
parent 2675f85598
commit b68e22c094
11 changed files with 1094 additions and 85 deletions
+11 -5
View File
@@ -303,6 +303,7 @@ class ProductSuiteGenerateWorker(BaseWorker):
project_id,
job_specs,
*,
run_token="",
aspect_ratio="1:1",
db_path=None,
config=None,
@@ -311,10 +312,12 @@ class ProductSuiteGenerateWorker(BaseWorker):
super().__init__()
self.project_id = int(project_id)
self.job_specs = [dict(spec) for spec in (job_specs or [])]
self.run_token = str(run_token or "")
self.aspect_ratio = str(aspect_ratio or "1:1")
self.db_path = db_path
self.config = config
self.cmhub_config_path = cmhub_config_path
self.job_ids = []
self._done = 0
self._failed = 0
self._lock = threading.Lock()
@@ -325,8 +328,6 @@ class ProductSuiteGenerateWorker(BaseWorker):
raise ValueError("商品套图生成任务不能为空")
jobs = []
for spec in self.job_specs:
if self.should_cancel():
break
jobs.append(
image_studio.create_job(
self.project_id,
@@ -338,12 +339,14 @@ class ProductSuiteGenerateWorker(BaseWorker):
path=self.db_path,
)
)
self.job_ids = [job.id for job in jobs]
self.progress.emit(
{
"run_token": self.run_token,
"total": len(jobs),
"done": 0,
"failed": 0,
"job_ids": [job.id for job in jobs],
"job_ids": list(self.job_ids),
}
)
@@ -356,10 +359,11 @@ class ProductSuiteGenerateWorker(BaseWorker):
if event.get("result") != "success":
self._failed += 1
progress = {
"run_token": self.run_token,
"total": len(jobs),
"done": self._done,
"failed": self._failed,
"job_ids": [job.id for job in jobs],
"job_ids": list(self.job_ids),
}
self.progress.emit(progress)
@@ -373,7 +377,9 @@ class ProductSuiteGenerateWorker(BaseWorker):
on_event=on_event,
)
summary["project_id"] = self.project_id
summary["job_ids"] = [job.id for job in jobs]
summary["job_ids"] = list(self.job_ids)
summary["cancelled_count"] = int(summary.get("cancelled", 0) or 0)
summary["run_token"] = self.run_token
return summary