feat: 串联生产跟踪持久化后台状态
This commit is contained in:
1 parent
00032cf30d
commit
f8e08b8574
1 file changed
+31
-5
@@ -1,9 +1,10 @@
|
||||
import { computed, onScopeDispose, ref, watch } from 'vue'
|
||||
import { computed, onScopeDispose, ref, watch undefined from 'vue'
|
||||
import { projectsApi } from '../projects/api'
|
||||
import { useProjectContext } from '../projects/context'
|
||||
import { subjectImagesApi } from '../subject-images/api'
|
||||
import { hasRunningImages } from '../subject-images/model'
|
||||
import { getOperation, runOperation } from '../workflows/operations'
|
||||
import { useWorkflowExecution } from '../workflows/execution'
|
||||
import { hasRunningWorkflow } from '../workflows/selectors'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
import { generationConfigApi } from '../generation-config/api'
|
||||
@@ -77,6 +78,7 @@ export function useAdvancedProduction() {
|
||||
const id = computed(() => context.project.value?.id ?? '')
|
||||
const operation = computed(() => getOperation(id.value))
|
||||
const session = computed(() => getProductionSession(id.value))
|
||||
const execution = useWorkflowExecution(id, 'production')
|
||||
const checking = ref(false)
|
||||
const error = ref('')
|
||||
/** 默认使用无视频测试模式,只有用户明确切换后才允许提交高费用视频任务。 */
|
||||
@@ -87,6 +89,7 @@ export function useAdvancedProduction() {
|
||||
() =>
|
||||
!id.value ||
|
||||
operation.value.pending ||
|
||||
execution.active.value ||
|
||||
!!context.error.value ||
|
||||
context.project.value?.status !== 'completed'
|
||||
)
|
||||
@@ -145,7 +148,7 @@ export function useAdvancedProduction() {
|
||||
if (result.issues.length) throw new Error('提交前预检发现条件变化,未启动生产。请处理下方问题。')
|
||||
target.pipelineReceipt = null
|
||||
submitted = true
|
||||
const receipt = await productionApi.startPipeline(projectId, {
|
||||
const started = await productionApi.startPipeline(projectId, {
|
||||
...(result.profile
|
||||
? {
|
||||
imageProvider: result.profile.imageProvider,
|
||||
@@ -159,19 +162,32 @@ export function useAdvancedProduction() {
|
||||
}
|
||||
: {})
|
||||
})
|
||||
if (!receipt || receipt.projectId !== projectId)
|
||||
throw new Error('回执项目不匹配,请读取资产状态核对,不要直接重试。')
|
||||
target.pipelineReceipt = receipt
|
||||
if (!started.executionId) throw new Error('后端未返回 Production executionId,请勿重复提交。')
|
||||
await execution.track(started.executionId)
|
||||
})
|
||||
if (!disposed && id.value === projectId) {
|
||||
if (submitted) check.value = null
|
||||
await context.refresh()
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => execution.query.data.value?.status,
|
||||
async (status, previous) => {
|
||||
if ((status === 'completed' || status === 'failed') && status !== previous) {
|
||||
const result = execution.query.data.value?.result
|
||||
if (status === 'completed' && result && typeof result === 'object') {
|
||||
targetPipelineReceipt(id.value, result, session.value)
|
||||
}
|
||||
await context.refresh()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
id,
|
||||
operation,
|
||||
session,
|
||||
execution,
|
||||
checking,
|
||||
error,
|
||||
check,
|
||||
@@ -182,3 +198,13 @@ export function useAdvancedProduction() {
|
||||
start
|
||||
}
|
||||
}
|
||||
|
||||
/** WorkflowExecution.result 只在完成后转成串联生产回执,运行中绝不伪造完成状态。 */
|
||||
function targetPipelineReceipt(
|
||||
projectId: string,
|
||||
result: object,
|
||||
session: ReturnType<typeof getProductionSession>
|
||||
) {
|
||||
if (!projectId || !('projectId' in result) || result.projectId !== projectId) return
|
||||
session.pipelineReceipt = result as import('./types').ProductionPipelineResult
|
||||
}
|
||||
Reference in new issue
Block a user