mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 06:30:10 +08:00
fix: infinite loop in knowledge queue processing (#11856)
* fix: infinite loop in knowledge queue processing * fix: address review comments
This commit is contained in:
parent
512d872ac3
commit
be9a8b8699
@ -163,6 +163,7 @@ export const useKnowledge = (baseId: string) => {
|
|||||||
processingProgress: 0,
|
processingProgress: 0,
|
||||||
processingError: '',
|
processingError: '',
|
||||||
uniqueId: undefined,
|
uniqueId: undefined,
|
||||||
|
retryCount: 0,
|
||||||
updated_at: Date.now()
|
updated_at: Date.now()
|
||||||
})
|
})
|
||||||
checkAllBases()
|
checkAllBases()
|
||||||
@ -182,6 +183,7 @@ export const useKnowledge = (baseId: string) => {
|
|||||||
processingProgress: 0,
|
processingProgress: 0,
|
||||||
processingError: '',
|
processingError: '',
|
||||||
uniqueId: undefined,
|
uniqueId: undefined,
|
||||||
|
retryCount: 0,
|
||||||
updated_at: Date.now()
|
updated_at: Date.now()
|
||||||
})
|
})
|
||||||
setTimeout(() => KnowledgeQueue.checkAllBases(), 0)
|
setTimeout(() => KnowledgeQueue.checkAllBases(), 0)
|
||||||
|
|||||||
@ -75,7 +75,7 @@ class KnowledgeQueue {
|
|||||||
|
|
||||||
let processableItem = findProcessableItem()
|
let processableItem = findProcessableItem()
|
||||||
while (processableItem) {
|
while (processableItem) {
|
||||||
this.processItem(baseId, processableItem).then()
|
await this.processItem(baseId, processableItem)
|
||||||
processableItem = findProcessableItem()
|
processableItem = findProcessableItem()
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -99,7 +99,27 @@ class KnowledgeQueue {
|
|||||||
const userId = getStoreSetting('userId')
|
const userId = getStoreSetting('userId')
|
||||||
try {
|
try {
|
||||||
if (item.retryCount && item.retryCount >= this.MAX_RETRIES) {
|
if (item.retryCount && item.retryCount >= this.MAX_RETRIES) {
|
||||||
logger.info(`Item ${item.id} has reached max retries, skipping`)
|
const errorMessage = item.processingError
|
||||||
|
? `Max retries exceeded: ${item.processingError}`
|
||||||
|
: 'Max retries exceeded'
|
||||||
|
logger.warn(`Item ${item.id} has reached max retries, marking as failed`)
|
||||||
|
notificationService.send({
|
||||||
|
id: uuid(),
|
||||||
|
type: 'error',
|
||||||
|
title: t('common.knowledge_base'),
|
||||||
|
message: t('notification.knowledge.error', { error: errorMessage }),
|
||||||
|
silent: false,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
source: 'knowledge'
|
||||||
|
})
|
||||||
|
store.dispatch(
|
||||||
|
updateItemProcessingStatus({
|
||||||
|
baseId,
|
||||||
|
itemId: item.id,
|
||||||
|
status: 'failed',
|
||||||
|
error: errorMessage
|
||||||
|
})
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user