From ebf36e614610d0efcdda264c25aa765620442c2c Mon Sep 17 00:00:00 2001 From: lifei6671 Date: Wed, 11 Jul 2018 11:30:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9B=AE=E5=BD=95=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=8F=AF?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AF=BC=E5=87=BA=E7=9A=84=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/app.conf.example | 9 +++++++-- conf/enumerate.go | 10 +++++++++- controllers/BookController.go | 2 +- controllers/DocumentController.go | 4 ++-- converter/converter.go | 2 -- models/BookResult.go | 7 +++++-- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/conf/app.conf.example b/conf/app.conf.example index f11d0fe0..3a785d09 100644 --- a/conf/app.conf.example +++ b/conf/app.conf.example @@ -13,7 +13,7 @@ beegoserversessionkey=123456 ########Session储存方式############## #以文件方式储存 sessionprovider=file -sessionproviderconfig=./logs +sessionproviderconfig=./runtime/session #以redis方式储存 #sessionprovider=redis #sessionproviderconfig=127.0.0.1:6379 @@ -73,14 +73,19 @@ mail_expired=30 #加密类型NONE 无认证、SSL 加密、LOGIN 普通用户登录 secure=LOGIN -###############配置PDF生成工具地址################### +###############配置导出项目################### #同一个项目同时运行导出程序的并行数量,取值1-4之间,取值越大导出速度越快,越占用资源 export_process_num=1 + #并发导出的项目限制,指同一时间限制的导出项目数量,如果为0则不限制。设置的越大,越占用资源 export_limit_num=1 + #指同时等待导出的任务数量 export_queue_limit_num=100 +#导出项目的缓存目录配置 +export_output_path=./runtime/cache + ###############配置CDN加速################## cdn= cdnjs= diff --git a/conf/enumerate.go b/conf/enumerate.go index 44708bea..ceeb9acf 100644 --- a/conf/enumerate.go +++ b/conf/enumerate.go @@ -6,6 +6,7 @@ import ( "github.com/astaxie/beego" "strconv" + "path/filepath" ) // 登录用户的Session名 @@ -65,7 +66,7 @@ var ( var ( ConfigurationFile = "./conf/app.conf" WorkingDirectory = "./" - LogFile = "./logs" + LogFile = "./runtime/logs" BaseUrl = "" ) @@ -90,6 +91,7 @@ func GetTokenSize() int { //获取默认文档封面. func GetDefaultCover() string { + return URLForWithCdnImage(beego.AppConfig.DefaultString("cover", "/static/images/book.jpg")) } @@ -162,6 +164,12 @@ func GetExportQueueLimitNum() int { } return exportQueueLimitNum } +//默认导出项目的缓存目录 +func GetExportOutputPath() string { + exportOutputPath := filepath.Join(beego.AppConfig.DefaultString("export_output_path", filepath.Join(WorkingDirectory,"cache")),"books") + + return exportOutputPath +} //判断是否是允许商城的文件类型. func IsAllowUploadFileExt(ext string) bool { diff --git a/controllers/BookController.go b/controllers/BookController.go index d63d5a73..ca95d537 100644 --- a/controllers/BookController.go +++ b/controllers/BookController.go @@ -707,7 +707,7 @@ func (c *BookController) Release() { models.NewBook().ReleaseContent(bookId) //当文档发布后,需要删除已缓存的转换项目 - outputPath := filepath.Join(beego.AppConfig.DefaultString("book_output_path", "cache"), strconv.Itoa(bookId)) + outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(bookId)) os.RemoveAll(outputPath) }(identify) diff --git a/controllers/DocumentController.go b/controllers/DocumentController.go index 2a738a0f..8b8cdb10 100644 --- a/controllers/DocumentController.go +++ b/controllers/DocumentController.go @@ -858,7 +858,7 @@ func (c *DocumentController) Export() { return } - outputPath := filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(bookResult.BookId)) + outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(bookResult.BookId)) pdfpath := filepath.Join(outputPath, "book.pdf") epubpath := filepath.Join(outputPath, "book.epub") @@ -1092,7 +1092,7 @@ func (c *DocumentController) DeleteHistory() { c.JsonResult(0, "ok") } - +//通过文档历史恢复文档 func (c *DocumentController) RestoreHistory() { c.Prepare() diff --git a/converter/converter.go b/converter/converter.go index 93aae977..79926a7e 100644 --- a/converter/converter.go +++ b/converter/converter.go @@ -193,13 +193,11 @@ func (convert *Converter) Convert() (err error) { group := sync.WaitGroup{} for { action, isClosed := <-convert.process - fmt.Println(action,isClosed) if action == nil && !isClosed { break; } group.Add(1) <- convert.limitChan - fmt.Println("正在处理") go func(group *sync.WaitGroup) { action() group.Done() diff --git a/models/BookResult.go b/models/BookResult.go index 9ea8c6ce..861c5cfb 100644 --- a/models/BookResult.go +++ b/models/BookResult.go @@ -216,9 +216,12 @@ func (m *BookResult) ToBookResult(book Book) *BookResult { //后台转换 func BackgroupConvert(sessionId string,bookResult *BookResult){ - exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() { + err := exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() { bookResult.Converter(sessionId) }) + if err != nil { + beego.Error("将导出任务加入任务队列失败 -> ",err) + } exportLimitWorkerChannel.Start() } @@ -227,7 +230,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) { convertBookResult := ConvertBookResult{} - outputPath := filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(m.BookId)) + outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(m.BookId)) viewPath := beego.BConfig.WebConfig.ViewsPath pdfpath := filepath.Join(outputPath, "book.pdf")