From 11f1f1d34dd633e3630fad785e28679f61feda99 Mon Sep 17 00:00:00 2001 From: lifei6671 Date: Wed, 11 Jul 2018 18:30:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=A3=E5=9C=A8=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E7=9A=84=E5=AF=BC=E5=87=BA=E9=A1=B9=E7=9B=AE=E5=86=8D?= =?UTF-8?q?=E6=AC=A1=E5=AF=BC=E5=87=BA=E6=97=B6=E6=8F=90=E7=A4=BA=E6=AD=A3?= =?UTF-8?q?=E5=9C=A8=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/DocumentController.go | 3 ++- models/BookResult.go | 2 ++ utils/gopool/gopool.go | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/controllers/DocumentController.go b/controllers/DocumentController.go index 3dfe0249..ca9045b8 100644 --- a/controllers/DocumentController.go +++ b/controllers/DocumentController.go @@ -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,"导出失败,请查看系统日志") } diff --git a/models/BookResult.go b/models/BookResult.go index d91c9ce1..9d11f423 100644 --- a/models/BookResult.go +++ b/models/BookResult.go @@ -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 } diff --git a/utils/gopool/gopool.go b/utils/gopool/gopool.go index 1ff82a73..b7197471 100644 --- a/utils/gopool/gopool.go +++ b/utils/gopool/gopool.go @@ -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