feat(product-suite): add direct job state machine
This commit is contained in:
+11
-9
@@ -262,7 +262,7 @@ class ImageStudioDownloadOriginalWorker(BaseWorker):
|
||||
|
||||
|
||||
class ImageStudioGenerateJobsWorker(BaseWorker):
|
||||
"""Run cmhub hosted image generation jobs for the AI studio."""
|
||||
"""Run frozen-source image generation jobs for the AI studio."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -285,12 +285,13 @@ class ImageStudioGenerateJobsWorker(BaseWorker):
|
||||
self.job_type = str(job_type or "main")
|
||||
self.aspect_ratio = str(aspect_ratio or "1:1")
|
||||
self.db_path = db_path
|
||||
backend = appconfig.ai_backend(config)
|
||||
self.config = ai.freeze_runtime_config(
|
||||
config,
|
||||
cmhub_config_path=cmhub_config_path,
|
||||
models_path=(config or {}).get("ai_models_path", appconfig.AI_MODELS_PATH),
|
||||
include_cmhub=True,
|
||||
include_direct_models=False,
|
||||
include_cmhub=backend == "cmhub",
|
||||
include_direct_models=backend == "direct",
|
||||
)
|
||||
self.cmhub_config_path = cmhub_config_path
|
||||
self._done = 0
|
||||
@@ -364,12 +365,13 @@ class ProductSuiteGenerateWorker(BaseWorker):
|
||||
self.generation_round_key = str(generation_round_key or "").strip()
|
||||
self.aspect_ratio = str(aspect_ratio or "1:1")
|
||||
self.db_path = db_path
|
||||
backend = appconfig.ai_backend(config)
|
||||
self.config = ai.freeze_runtime_config(
|
||||
config,
|
||||
cmhub_config_path=cmhub_config_path,
|
||||
models_path=(config or {}).get("ai_models_path", appconfig.AI_MODELS_PATH),
|
||||
include_cmhub=True,
|
||||
include_direct_models=False,
|
||||
include_cmhub=backend == "cmhub",
|
||||
include_direct_models=backend == "direct",
|
||||
)
|
||||
self.cmhub_config_path = cmhub_config_path
|
||||
self.job_ids = []
|
||||
@@ -378,12 +380,11 @@ class ProductSuiteGenerateWorker(BaseWorker):
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def execute(self):
|
||||
if appconfig.ai_backend(self.config) != "cmhub":
|
||||
raise ValueError("商品套图仅支持默认网关,请到⑤设置切换后再生成")
|
||||
total = len(self.job_specs)
|
||||
if total <= 0:
|
||||
raise ValueError("商品套图生成任务不能为空")
|
||||
jobs = []
|
||||
source = image_studio_generation.generation_source_for_config(self.config)
|
||||
for spec in self.job_specs:
|
||||
jobs.append(
|
||||
image_studio.create_job(
|
||||
@@ -392,8 +393,8 @@ class ProductSuiteGenerateWorker(BaseWorker):
|
||||
reference_asset_ids=spec.get("reference_asset_ids"),
|
||||
job_type=spec.get("job_type") or "套图",
|
||||
prompt=spec.get("prompt") or "",
|
||||
generation_source="cmhub",
|
||||
provider="cmhub",
|
||||
generation_source=source["generation_source"],
|
||||
provider=source["provider"],
|
||||
generation_round_key=spec.get("generation_round_key") or self.generation_round_key or None,
|
||||
generation_slot_index=spec.get("generation_slot_index"),
|
||||
path=self.db_path,
|
||||
@@ -435,6 +436,7 @@ class ProductSuiteGenerateWorker(BaseWorker):
|
||||
path=self.db_path,
|
||||
should_stop=self.should_cancel,
|
||||
on_event=on_event,
|
||||
run_session_id=self.run_token,
|
||||
)
|
||||
summary["project_id"] = self.project_id
|
||||
summary["job_ids"] = list(self.job_ids)
|
||||
|
||||
Reference in New Issue
Block a user