mirror of
https://github.com/langgenius/dify.git
synced 2026-06-17 14:51:10 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Co-authored-by: gigglewang <gigglewang@dify.ai> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: chariri <w@chariri.moe> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import type { PluginStatus } from '../../types'
|
|
import { checkTaskStatus as fetchCheckTaskStatus } from '@/service/plugins'
|
|
import { sleep } from '@/utils'
|
|
import { TaskStatus } from '../../types'
|
|
|
|
const INTERVAL = 10 * 1000 // 10 seconds
|
|
const isUnfinishedStatus = (status: TaskStatus) => status === TaskStatus.pending || status === TaskStatus.running
|
|
|
|
type Params = {
|
|
taskId: string
|
|
pluginUniqueIdentifier: string
|
|
}
|
|
|
|
function checkTaskStatus() {
|
|
let nextStatus = TaskStatus.running
|
|
let isStop = false
|
|
|
|
const doCheckStatus = async ({
|
|
taskId,
|
|
pluginUniqueIdentifier,
|
|
}: Params) => {
|
|
if (isStop) {
|
|
return {
|
|
status: TaskStatus.success,
|
|
}
|
|
}
|
|
const res = await fetchCheckTaskStatus(taskId)
|
|
const { plugins } = res.task
|
|
const plugin = plugins.find((p: PluginStatus) => p.plugin_unique_identifier === pluginUniqueIdentifier)
|
|
if (!plugin) {
|
|
nextStatus = TaskStatus.failed
|
|
return {
|
|
status: TaskStatus.failed,
|
|
error: 'Plugin package not found',
|
|
}
|
|
}
|
|
nextStatus = plugin.status
|
|
if (isUnfinishedStatus(nextStatus)) {
|
|
await sleep(INTERVAL)
|
|
return await doCheckStatus({
|
|
taskId,
|
|
pluginUniqueIdentifier,
|
|
})
|
|
}
|
|
if (nextStatus === TaskStatus.failed) {
|
|
return {
|
|
status: TaskStatus.failed,
|
|
error: plugin.message,
|
|
}
|
|
}
|
|
return ({
|
|
status: TaskStatus.success,
|
|
})
|
|
}
|
|
|
|
return {
|
|
check: doCheckStatus,
|
|
stop: () => {
|
|
isStop = true
|
|
},
|
|
}
|
|
}
|
|
|
|
export default checkTaskStatus
|