mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
♻️ 后台任务队列支持设置超时 Fix https://github.com/siyuan-note/siyuan/issues/7331
This commit is contained in:
parent
a6d945a9a1
commit
5e254500ef
4 changed files with 15 additions and 13 deletions
|
|
@ -209,7 +209,7 @@ func IndexRefs() {
|
||||||
// IndexEmbedBlockJob 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
|
// IndexEmbedBlockJob 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
|
||||||
func IndexEmbedBlockJob() {
|
func IndexEmbedBlockJob() {
|
||||||
embedBlocks := sql.QueryEmptyContentEmbedBlocks()
|
embedBlocks := sql.QueryEmptyContentEmbedBlocks()
|
||||||
task.AppendTask(task.DatabaseIndexEmbedBlock, autoIndexEmbedBlock, embedBlocks)
|
task.AppendTaskWithTimeout(task.DatabaseIndexEmbedBlock, 30*time.Second, autoIndexEmbedBlock, embedBlocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func autoIndexEmbedBlock(embedBlocks []*sql.Block) {
|
func autoIndexEmbedBlock(embedBlocks []*sql.Block) {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ func OCRAssetsJob() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
task.AppendTask(task.OCRImage, autoOCRAssets)
|
task.AppendTaskWithTimeout(task.OCRImage, 7*time.Second, autoOCRAssets)
|
||||||
}
|
}
|
||||||
|
|
||||||
func autoOCRAssets() {
|
func autoOCRAssets() {
|
||||||
|
|
@ -39,7 +39,7 @@ func autoOCRAssets() {
|
||||||
util.AssetsTextsLock.Unlock()
|
util.AssetsTextsLock.Unlock()
|
||||||
util.AssetsTextsChanged = true
|
util.AssetsTextsChanged = true
|
||||||
|
|
||||||
if 16 <= i { // 一次任务中最多处理 16 张图片,防止卡顿
|
if 4 <= i { // 一次任务中最多处理 4 张图片,防止卡顿
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ func searchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMod
|
||||||
}
|
}
|
||||||
|
|
||||||
// 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
|
// 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
|
||||||
task.AppendTask(task.DatabaseIndexEmbedBlock, updateEmbedBlockContent, embedBlockID, ret)
|
task.AppendTaskWithTimeout(task.DatabaseIndexEmbedBlock, 30*time.Second, updateEmbedBlockContent, embedBlockID, ret)
|
||||||
|
|
||||||
// 添加笔记本名称
|
// 添加笔记本名称
|
||||||
var boxIDs []string
|
var boxIDs []string
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,14 @@ type Task struct {
|
||||||
Handler reflect.Value
|
Handler reflect.Value
|
||||||
Args []interface{}
|
Args []interface{}
|
||||||
Created time.Time
|
Created time.Time
|
||||||
|
Timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppendTask(action string, handler interface{}, args ...interface{}) {
|
func AppendTask(action string, handler interface{}, args ...interface{}) {
|
||||||
|
AppendTaskWithTimeout(action, 24*time.Hour, handler, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AppendTaskWithTimeout(action string, timeout time.Duration, handler interface{}, args ...interface{}) {
|
||||||
if util.IsExiting {
|
if util.IsExiting {
|
||||||
//logging.LogWarnf("task queue is paused, action [%s] will be ignored", action)
|
//logging.LogWarnf("task queue is paused, action [%s] will be ignored", action)
|
||||||
return
|
return
|
||||||
|
|
@ -53,16 +58,13 @@ func AppendTask(action string, handler interface{}, args ...interface{}) {
|
||||||
|
|
||||||
queueLock.Lock()
|
queueLock.Lock()
|
||||||
defer queueLock.Unlock()
|
defer queueLock.Unlock()
|
||||||
taskQueue = append(taskQueue, newTask(action, handler, args...))
|
taskQueue = append(taskQueue, &Task{
|
||||||
}
|
|
||||||
|
|
||||||
func newTask(action string, handler interface{}, args ...interface{}) *Task {
|
|
||||||
return &Task{
|
|
||||||
Action: action,
|
Action: action,
|
||||||
|
Timeout: timeout,
|
||||||
Handler: reflect.ValueOf(handler),
|
Handler: reflect.ValueOf(handler),
|
||||||
Args: args,
|
Args: args,
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCurrentActions() (ret []string) {
|
func getCurrentActions() (ret []string) {
|
||||||
|
|
@ -166,8 +168,6 @@ func ExecTaskJob() {
|
||||||
execTask(task)
|
execTask(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentTaskAction string
|
|
||||||
|
|
||||||
func popTask() (ret *Task) {
|
func popTask() (ret *Task) {
|
||||||
queueLock.Lock()
|
queueLock.Lock()
|
||||||
defer queueLock.Unlock()
|
defer queueLock.Unlock()
|
||||||
|
|
@ -181,6 +181,8 @@ func popTask() (ret *Task) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentTaskAction string
|
||||||
|
|
||||||
func execTask(task *Task) {
|
func execTask(task *Task) {
|
||||||
defer logging.Recover()
|
defer logging.Recover()
|
||||||
|
|
||||||
|
|
@ -195,7 +197,7 @@ func execTask(task *Task) {
|
||||||
|
|
||||||
currentTaskAction = task.Action
|
currentTaskAction = task.Action
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), task.Timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ch := make(chan bool, 1)
|
ch := make(chan bool, 1)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue