feat: Improve file upload for the knowledge base (#2544)
* feat: Improve file upload for the knowledge base * feat: Improve file upload for the knowledge base * feat: Improve file upload for the knowledge base --------- Co-authored-by: 亢奋猫 <kangfenmao@qq.com>
This commit is contained in:
@@ -51,20 +51,24 @@ class KnowledgeQueue {
|
||||
throw new Error('Knowledge base not found')
|
||||
}
|
||||
|
||||
const processableItems = base.items.filter((item) => {
|
||||
if (item.processingStatus === 'failed') {
|
||||
return !item.retryCount || item.retryCount < this.MAX_RETRIES
|
||||
}
|
||||
return item.processingStatus === 'pending'
|
||||
})
|
||||
const findProcessableItem = () => {
|
||||
const state = store.getState()
|
||||
const base = state.knowledge.bases.find((b) => b.id === baseId)
|
||||
return (
|
||||
base?.items.find((item) => {
|
||||
if (item.processingStatus === 'failed') {
|
||||
return !item.retryCount || item.retryCount < this.MAX_RETRIES
|
||||
} else {
|
||||
return item.processingStatus === 'pending'
|
||||
}
|
||||
}) ?? null
|
||||
)
|
||||
}
|
||||
|
||||
for (const item of processableItems) {
|
||||
if (!this.processing.get(baseId)) {
|
||||
console.log(`[KnowledgeQueue] Processing interrupted for base ${baseId}`)
|
||||
break
|
||||
}
|
||||
|
||||
this.processItem(baseId, item)
|
||||
let processableItem = findProcessableItem()
|
||||
while (processableItem) {
|
||||
this.processItem(baseId, processableItem).then()
|
||||
processableItem = findProcessableItem()
|
||||
}
|
||||
} finally {
|
||||
console.log(`[KnowledgeQueue] Finished processing queue for base ${baseId}`)
|
||||
@@ -153,7 +157,7 @@ class KnowledgeQueue {
|
||||
}
|
||||
console.debug(`[KnowledgeQueue] Updated uniqueId for item ${item.id} in base ${baseId} `)
|
||||
|
||||
setTimeout(() => store.dispatch(clearCompletedProcessing({ baseId })), 1000)
|
||||
store.dispatch(clearCompletedProcessing({ baseId }))
|
||||
} catch (error) {
|
||||
console.error(`[KnowledgeQueue] Error processing item ${item.id}: `, error)
|
||||
store.dispatch(
|
||||
|
||||
Reference in New Issue
Block a user