feat: 形态图片任务运行时临时轮询
This commit is contained in:
1 parent
3f9f2aab24
commit
7432c964b1
1 file changed
+9
-1
@@ -9,6 +9,11 @@ import { subjectImagesApi } from './api'
|
||||
import { getImageSession, hasRunningImages } from './model'
|
||||
import type { GenerateFormImageInput, SubjectModule } from './types'
|
||||
|
||||
/** 仅后台图片任务存在时开启临时轮询,终态后自动停止。 */
|
||||
function queryDataHasRunningImages(forms: Awaited<ReturnType<typeof subjectImagesApi.listForms>> | null) {
|
||||
return forms?.some(form => hasRunningImages(form.images)) ?? false
|
||||
}
|
||||
|
||||
/** 形态图库统一读取数据库记录并管理单图/批量长请求,不调用生产流程。 */
|
||||
export function useSubjectImages() {
|
||||
const context = useProjectContext()
|
||||
@@ -29,6 +34,9 @@ export function useSubjectImages() {
|
||||
async (projectId, signal) => ({ profile: await generationConfigApi.profile(projectId, signal) }),
|
||||
false
|
||||
)
|
||||
const pollInterval = computed(() =>
|
||||
queryDataHasRunningImages(query.data.value) ? 4000 : false
|
||||
)
|
||||
const query = usePolling(
|
||||
id,
|
||||
async (projectId, signal) => {
|
||||
@@ -53,7 +61,7 @@ export function useSubjectImages() {
|
||||
throw error
|
||||
}
|
||||
},
|
||||
false
|
||||
pollInterval
|
||||
)
|
||||
const forms = computed(() => query.data.value ?? [])
|
||||
const operation = computed(() => getOperation(id.value))
|
||||
|
||||
Reference in new issue
Block a user