Commit 8570754f by Li Feifei

test

parent c8ce46fa
Pipeline #14620 failed with stages
in 39 seconds
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"github.com/chai2010/webp" "github.com/chai2010/webp"
"github.com/xxjwxc/gowp/workpool"
"image" "image"
"image/jpeg" "image/jpeg"
"image/png" "image/png"
...@@ -27,6 +28,7 @@ import ( ...@@ -27,6 +28,7 @@ import (
"runtime/debug" "runtime/debug"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
) )
...@@ -36,13 +38,19 @@ var ( ...@@ -36,13 +38,19 @@ var (
WEBURL string = "https://test-live.offcncloud.com" WEBURL string = "https://test-live.offcncloud.com"
client *http.Client client *http.Client
token string token string
once sync.Once
Pool *workpool.WorkPool
) )
const docUrl string = "http://doc.offcncloud.com/" const docUrl string = "http://doc.offcncloud.com/"
func init() {
once.Do(func() {
Pool = workpool.New(10)
})
}
//func main() { //func main() {
...@@ -253,44 +261,58 @@ func Down(v *models.XyuSmallTempFiles) { ...@@ -253,44 +261,58 @@ func Down(v *models.XyuSmallTempFiles) {
ch1 := make(chan bool) ch1 := make(chan bool)
for _, file := range reader.File { for _, file := range reader.File {
Pool.DoWait(func() error {
go func(file *zip.File) { var err error
defer debug.FreeOSMemory()
err := pdfThumbnail(objectPath, file, bucket)
if err != nil {
fmt.Println(objectPath + file.Name + "上传失败")
// 上传缩略图失败,重试3次
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
err = pdfThumbnail(objectPath, file, bucket) if err = pdfThumbnail(objectPath, file, bucket); err == nil {
if err == nil { break
ch1 <- true
return
}
}
UpdateFileError("5", v.Uuid, v.RoomNum, objectName)
ch1 <- false
return
} else {
ch1 <- true
return
}
}(file)
} }
for i := 0; i < int(wordFloat64); i++ {
t := <-ch1
if t {
uploadImageCount++
} }
return err
})
//go func(file *zip.File) {
// defer debug.FreeOSMemory()
// err := pdfThumbnail(objectPath, file, bucket)
//
// if err != nil {
// fmt.Println(objectPath + file.Name + "上传失败")
// // 上传缩略图失败,重试3次
// for i := 0; i < 3; i++ {
// err = pdfThumbnail(objectPath, file, bucket)
// if err == nil {
// ch1 <- true
// return
// }
// }
// UpdateFileError("5", v.Uuid, v.RoomNum, objectName)
// ch1 <- false
// return
// } else {
// ch1 <- true
// return
// }
//
//}(file)
} }
defer reader.Close() //for i := 0; i < int(wordFloat64); i++ {
fmt.Println(uploadImageCount, wordFloat64) // t := <-ch1
if uploadImageCount != wordFloat64 { // if t {
// uploadImageCount++
// }
//}
err = Pool.Wait()
if err != nil {
UpdateFileError("5", v.Uuid, v.RoomNum, objectName) UpdateFileError("5", v.Uuid, v.RoomNum, objectName)
fmt.Println("上传失败") fmt.Println(err)
return return
} }
defer reader.Close()
//fmt.Println(uploadImageCount, wordFloat64)
//if uploadImageCount != wordFloat64 {
// UpdateFileError("5", v.Uuid, v.RoomNum, objectName)
// fmt.Println("上传失败")
// return
//}
go func() { go func() {
err := uploadPacked(bucket, filename, contentHash, objectPath, err := uploadPacked(bucket, filename, contentHash, objectPath,
...@@ -487,6 +509,7 @@ func CreateFileDataBase(room_file map[string]interface{}) error { ...@@ -487,6 +509,7 @@ func CreateFileDataBase(room_file map[string]interface{}) error {
return nil return nil
} }
func pdfThumbnail(objectPath string, file *zip.File, bucket *oss.Bucket) error { func pdfThumbnail(objectPath string, file *zip.File, bucket *oss.Bucket) error {
fc, err := file.Open() fc, err := file.Open()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment