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 { projectsApi } from '../projects/api'
|
||||||
import { useProjectContext } from '../projects/context'
|
import { useProjectContext } from '../projects/context'
|
||||||
import { subjectImagesApi } from '../subject-images/api'
|
import { subjectImagesApi } from '../subject-images/api'
|
||||||
import { hasRunningImages } from '../subject-images/model'
|
import { hasRunningImages } from '../subject-images/model'
|
||||||
import { getOperation, runOperation } from '../workflows/operations'
|
import { getOperation, runOperation } from '../workflows/operations'
|
||||||
|
import { useWorkflowExecution } from '../workflows/execution'
|
||||||
import { hasRunningWorkflow } from '../workflows/selectors'
|
import { hasRunningWorkflow } from '../workflows/selectors'
|
||||||
import { errorMessage } from '../../lib/http'
|
import { errorMessage } from '../../lib/http'
|
||||||
import { generationConfigApi } from '../generation-config/api'
|
import { generationConfigApi } from '../generation-config/api'
|
||||||
@@ -77,6 +78,7 @@ export function useAdvancedProduction() {
|
|||||||
const id = computed(() => context.project.value?.id ?? '')
|
const id = computed(() => context.project.value?.id ?? '')
|
||||||
const operation = computed(() => getOperation(id.value))
|
const operation = computed(() => getOperation(id.value))
|
||||||
const session = computed(() => getProductionSession(id.value))
|
const session = computed(() => getProductionSession(id.value))
|
||||||
|
const execution = useWorkflowExecution(id, 'production')
|
||||||
const checking = ref(false)
|
const checking = ref(false)
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
/** 默认使用无视频测试模式,只有用户明确切换后才允许提交高费用视频任务。 */
|
/** 默认使用无视频测试模式,只有用户明确切换后才允许提交高费用视频任务。 */
|
||||||
@@ -87,6 +89,7 @@ export function useAdvancedProduction() {
|
|||||||
() =>
|
() =>
|
||||||
!id.value ||
|
!id.value ||
|
||||||
operation.value.pending ||
|
operation.value.pending ||
|
||||||
|
execution.active.value ||
|
||||||
!!context.error.value ||
|
!!context.error.value ||
|
||||||
context.project.value?.status !== 'completed'
|
context.project.value?.status !== 'completed'
|
||||||
)
|
)
|
||||||
@@ -145,7 +148,7 @@ export function useAdvancedProduction() {
|
|||||||
if (result.issues.length) throw new Error('提交前预检发现条件变化,未启动生产。请处理下方问题。')
|
if (result.issues.length) throw new Error('提交前预检发现条件变化,未启动生产。请处理下方问题。')
|
||||||
target.pipelineReceipt = null
|
target.pipelineReceipt = null
|
||||||
submitted = true
|
submitted = true
|
||||||
const receipt = await productionApi.startPipeline(projectId, {
|
const started = await productionApi.startPipeline(projectId, {
|
||||||
...(result.profile
|
...(result.profile
|
||||||
? {
|
? {
|
||||||
imageProvider: result.profile.imageProvider,
|
imageProvider: result.profile.imageProvider,
|
||||||
@@ -159,19 +162,32 @@ export function useAdvancedProduction() {
|
|||||||
}
|
}
|
||||||
: {})
|
: {})
|
||||||
})
|
})
|
||||||
if (!receipt || receipt.projectId !== projectId)
|
if (!started.executionId) throw new Error('后端未返回 Production executionId,请勿重复提交。')
|
||||||
throw new Error('回执项目不匹配,请读取资产状态核对,不要直接重试。')
|
await execution.track(started.executionId)
|
||||||
target.pipelineReceipt = receipt
|
|
||||||
})
|
})
|
||||||
if (!disposed && id.value === projectId) {
|
if (!disposed && id.value === projectId) {
|
||||||
if (submitted) check.value = null
|
if (submitted) check.value = null
|
||||||
await context.refresh()
|
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 {
|
return {
|
||||||
id,
|
id,
|
||||||
operation,
|
operation,
|
||||||
session,
|
session,
|
||||||
|
execution,
|
||||||
checking,
|
checking,
|
||||||
error,
|
error,
|
||||||
check,
|
check,
|
||||||
@@ -182,3 +198,13 @@ export function useAdvancedProduction() {
|
|||||||
start
|
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