+5
![dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)
![autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)







Jingyi
GitHub
yyh
Joel
hjlarry
fatelei
Asuka Minato
autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Xiyuan Chen
gigglewang
Yunlu Wen
chariri
Evan
yyh
9b74df21d0
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: yyh <[email protected]> Co-authored-by: Joel <[email protected]> Co-authored-by: hjlarry <[email protected]> Co-authored-by: fatelei <[email protected]> Co-authored-by: Asuka Minato <[email protected]> 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 <[email protected]> Co-authored-by: gigglewang <[email protected]> Co-authored-by: Yunlu Wen <[email protected]> Co-authored-by: chariri <[email protected]> Co-authored-by: Evan <[email protected]> Co-authored-by: yyh <[email protected]>
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
|