优化正在运行的导出项目再次导出时提示正在运行

pull/358/head
lifei6671 2018-07-11 18:30:28 +08:00
parent cf043c25a3
commit 11f1f1d34d
3 changed files with 8 additions and 5 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/lifei6671/mindoc/utils/cryptil"
"fmt"
"github.com/lifei6671/mindoc/utils/filetil"
"github.com/lifei6671/mindoc/utils/gopool"
)
// DocumentController struct
@ -882,7 +883,7 @@ func (c *DocumentController) Export() {
c.Abort("200")
}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,"导出失败,请查看系统日志")
}

View File

@ -224,7 +224,9 @@ func BackgroupConvert(sessionId string,bookResult *BookResult) error {
err := exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() {
bookResult.Converter(sessionId)
})
if err != nil {
beego.Error("将导出任务加入任务队列失败 -> ",err)
return err
}

View File

@ -6,8 +6,8 @@ import (
"fmt"
)
var (
HandlerIsExistErr = errors.New("指定的键已存在")
WorkerChanClosedErr = errors.New("队列已关闭")
ErrHandlerIsExist = errors.New("指定的键已存在")
ErrWorkerChanClosed = errors.New("队列已关闭")
)
type ChannelHandler func()
@ -48,10 +48,10 @@ func NewChannelPool(maxWorkerNum, maxPoolNum int) (*ChannelPool) {
func (pool *ChannelPool) LoadOrStore(key string,value ChannelHandler) error {
if pool.isClosed {
return WorkerChanClosedErr
return ErrWorkerChanClosed
}
if _,loaded := pool.cache.LoadOrStore(key,false); loaded {
return HandlerIsExistErr
return ErrHandlerIsExist
}else{
pool.worker <- &entry{handler:value,key:key}
return nil