mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-04-05 14:43:47 +08:00
优化正在运行的导出项目再次导出时提示正在运行
This commit is contained in:
parent
cf043c25a3
commit
11f1f1d34d
@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/lifei6671/mindoc/utils/cryptil"
|
"github.com/lifei6671/mindoc/utils/cryptil"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/lifei6671/mindoc/utils/filetil"
|
"github.com/lifei6671/mindoc/utils/filetil"
|
||||||
|
"github.com/lifei6671/mindoc/utils/gopool"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DocumentController struct
|
// DocumentController struct
|
||||||
@ -882,7 +883,7 @@ func (c *DocumentController) Export() {
|
|||||||
c.Abort("200")
|
c.Abort("200")
|
||||||
|
|
||||||
}else if output == "pdf" || output == "epub" || output == "docx" || output == "mobi"{
|
}else if output == "pdf" || output == "epub" || output == "docx" || output == "mobi"{
|
||||||
if err := models.BackgroupConvert(c.CruSession.SessionID(),bookResult);err != nil {
|
if err := models.BackgroupConvert(c.CruSession.SessionID(),bookResult);err != nil && err != gopool.ErrHandlerIsExist{
|
||||||
c.ShowErrorPage(500,"导出失败,请查看系统日志")
|
c.ShowErrorPage(500,"导出失败,请查看系统日志")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,9 @@ func BackgroupConvert(sessionId string,bookResult *BookResult) error {
|
|||||||
err := exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() {
|
err := exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() {
|
||||||
bookResult.Converter(sessionId)
|
bookResult.Converter(sessionId)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
beego.Error("将导出任务加入任务队列失败 -> ",err)
|
beego.Error("将导出任务加入任务队列失败 -> ",err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
HandlerIsExistErr = errors.New("指定的键已存在")
|
ErrHandlerIsExist = errors.New("指定的键已存在")
|
||||||
WorkerChanClosedErr = errors.New("队列已关闭")
|
ErrWorkerChanClosed = errors.New("队列已关闭")
|
||||||
)
|
)
|
||||||
type ChannelHandler func()
|
type ChannelHandler func()
|
||||||
|
|
||||||
@ -48,10 +48,10 @@ func NewChannelPool(maxWorkerNum, maxPoolNum int) (*ChannelPool) {
|
|||||||
|
|
||||||
func (pool *ChannelPool) LoadOrStore(key string,value ChannelHandler) error {
|
func (pool *ChannelPool) LoadOrStore(key string,value ChannelHandler) error {
|
||||||
if pool.isClosed {
|
if pool.isClosed {
|
||||||
return WorkerChanClosedErr
|
return ErrWorkerChanClosed
|
||||||
}
|
}
|
||||||
if _,loaded := pool.cache.LoadOrStore(key,false); loaded {
|
if _,loaded := pool.cache.LoadOrStore(key,false); loaded {
|
||||||
return HandlerIsExistErr
|
return ErrHandlerIsExist
|
||||||
}else{
|
}else{
|
||||||
pool.worker <- &entry{handler:value,key:key}
|
pool.worker <- &entry{handler:value,key:key}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user