diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 0c4d99206..ad3f3f7cf 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -753,6 +753,8 @@ MINIO_LOCATION = us-east-1 MINIO_BASE_PATH = attachments/ ; Minio enabled ssl only available when STORE_TYPE is `minio` MINIO_USE_SSL = false +; real Minio storage path +MINIO_REAL_PATH = /mnt/test/minio/data/ [time] ; Specifies the format for fully outputted dates. Defaults to RFC1123 diff --git a/main.go b/main.go index e25ce18b1..297bb24f7 100755 --- a/main.go +++ b/main.go @@ -22,7 +22,6 @@ import ( _ "code.gitea.io/gitea/modules/markup/markdown" _ "code.gitea.io/gitea/modules/markup/orgmode" _ "code.gitea.io/gitea/modules/timer" - _ "code.gitea.io/gitea/modules/worker" "github.com/urfave/cli" ) diff --git a/models/attachment.go b/models/attachment.go index f6c706e4e..afb2bbe16 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -28,19 +28,19 @@ const ( // Attachment represent a attachment of issue/comment/release. type Attachment struct { - ID int64 `xorm:"pk autoincr"` - UUID string `xorm:"uuid UNIQUE"` - IssueID int64 `xorm:"INDEX"` - DatasetID int64 `xorm:"INDEX DEFAULT 0"` - ReleaseID int64 `xorm:"INDEX"` - UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added - CommentID int64 - Name string - DownloadCount int64 `xorm:"DEFAULT 0"` - Size int64 `xorm:"DEFAULT 0"` - IsPrivate bool `xorm:"DEFAULT false"` - DecompressState int32 `xorm:"DEFAULT 0"` - CreatedUnix timeutil.TimeStamp `xorm:"created"` + ID int64 `xorm:"pk autoincr"` + UUID string `xorm:"uuid UNIQUE"` + IssueID int64 `xorm:"INDEX"` + DatasetID int64 `xorm:"INDEX DEFAULT 0"` + ReleaseID int64 `xorm:"INDEX"` + UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added + CommentID int64 + Name string + DownloadCount int64 `xorm:"DEFAULT 0"` + Size int64 `xorm:"DEFAULT 0"` + IsPrivate bool `xorm:"DEFAULT false"` + DecompressState int32 `xorm:"DEFAULT 0"` + CreatedUnix timeutil.TimeStamp `xorm:"created"` } func (a *Attachment) AfterUpdate() { diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 367a8d876..00d84da2e 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -212,7 +212,6 @@ var migrations = []Migration{ NewMigration("Add ResolveDoerID to Comment table", addResolveDoerIDCommentColumn), // v139 -> v140 NewMigration("prepend refs/heads/ to issue refs", prependRefsHeadsToIssueRefs), - NewMigration("add dataset migration", addDatasetTable), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v140.go b/models/migrations/v140.go deleted file mode 100644 index 9accefac0..000000000 --- a/models/migrations/v140.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2019 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package migrations - -import ( - "fmt" - - "code.gitea.io/gitea/modules/timeutil" - "xorm.io/xorm" -) - -func addDatasetTable(x *xorm.Engine) error { - type Dataset struct { - ID int64 `xorm:"pk autoincr"` - Title string `xorm:"INDEX NOT NULL"` - Status int32 `xorm:"INDEX"` - Category string - Description string `xorm:"TEXT"` - DownloadTimes int64 - License string - Task string - ReleaseID int64 `xorm:"INDEX"` - UserID int64 `xorm:"INDEX"` - RepoID int64 `xorm:"INDEX"` - CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` - UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` - } - - if err := x.Sync2(new(Dataset)); err != nil { - return fmt.Errorf("Sync2: %v", err) - } - return nil -} diff --git a/modules/decompression/decompression.go b/modules/decompression/decompression.go new file mode 100644 index 000000000..30c6b477c --- /dev/null +++ b/modules/decompression/decompression.go @@ -0,0 +1,7 @@ +package decompression + +import "code.gitea.io/gitea/modules/worker" + +func NewContext() { + worker.NewTaskCenter() +} diff --git a/modules/setting/setting.go b/modules/setting/setting.go index cd24597b9..926d643b1 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -420,9 +420,9 @@ var ( UILocation = time.Local //Machinery config - Broker string - DefaultQueue string - ResultBackend string + Broker string + DefaultQueue string + ResultBackend string ) // DateLang transforms standard language locale name to corresponding value in datetime plugin. diff --git a/modules/timer/timer.go b/modules/timer/timer.go index f74bb3a11..0d47102c0 100755 --- a/modules/timer/timer.go +++ b/modules/timer/timer.go @@ -7,15 +7,15 @@ import ( ) const ( - DecompressTimer = time.Minute * 10 + DecompressTimer = time.Minute * 10 ) func init() { ticker := time.NewTicker(DecompressTimer) go func() { for { - <- ticker.C + <-ticker.C repo.HandleUnDecompressAttachment() } - } () + }() } diff --git a/modules/worker/task.go b/modules/worker/task.go index 93aee3ecd..073b16b92 100755 --- a/modules/worker/task.go +++ b/modules/worker/task.go @@ -10,10 +10,10 @@ import ( // 方法名 const ( - DecompressTaskName = "Decompress" + DecompressTaskName = "Decompress" ) -func SendDecompressTask(ctx context.Context, uuid string) error{ +func SendDecompressTask(ctx context.Context, uuid string) error { args := []tasks.Arg{{Name: "uuid", Type: "string", Value: uuid}} task, err := tasks.NewSignature(DecompressTaskName, args) if err != nil { @@ -22,7 +22,7 @@ func SendDecompressTask(ctx context.Context, uuid string) error{ } task.RetryCount = 3 - _,err = AsyncTaskCenter.SendTaskWithContext(ctx, task) + _, err = AsyncTaskCenter.SendTaskWithContext(ctx, task) if err != nil { log.Error("SendTaskWithContext failed:", err.Error()) return err diff --git a/modules/worker/worker.go b/modules/worker/worker.go index 0f725a538..37445c978 100755 --- a/modules/worker/worker.go +++ b/modules/worker/worker.go @@ -1,6 +1,7 @@ package worker import ( + "code.gitea.io/gitea/modules/setting" "github.com/RichardKnop/machinery/v1" mchConf "github.com/RichardKnop/machinery/v1/config" ) @@ -9,21 +10,15 @@ var ( AsyncTaskCenter *machinery.Server ) -func init() { - tc, err := NewTaskCenter() +func NewTaskCenter() { + cnf := &mchConf.Config{ + Broker: setting.Broker, + DefaultQueue: setting.DefaultQueue, + ResultBackend: setting.ResultBackend, + } + tc, err := machinery.NewServer(cnf) if err != nil { panic(err) } AsyncTaskCenter = tc } - -func NewTaskCenter() (*machinery.Server, error) { - cnf := &mchConf.Config{ - Broker: "redis://localhost:6379", - DefaultQueue: "DecompressTasksQueue", - ResultBackend: "redis://localhost:6379", - } - // Create server instance - return machinery.NewServer(cnf) -} - diff --git a/routers/init.go b/routers/init.go old mode 100644 new mode 100755 index f899e8ad9..dafe0a202 --- a/routers/init.go +++ b/routers/init.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/auth/sso" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/cron" + "code.gitea.io/gitea/modules/decompression" "code.gitea.io/gitea/modules/eventsource" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/highlight" @@ -61,6 +62,7 @@ func NewServices() { mailer.NewContext() _ = cache.NewContext() notification.NewContext() + decompression.NewContext() } // In case of problems connecting to DB, retry connection. Eg, PGSQL in Docker Container on Synology diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 416815e50..297ed9ce3 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -27,8 +27,8 @@ import ( const ( //result of decompress - DecompressSuccess = "0" - DecompressFailed = "1" + DecompressSuccess = "0" + DecompressFailed = "1" ) func RenderAttachmentSettings(ctx *context.Context) { @@ -549,13 +549,13 @@ func UpdateMultipart(ctx *context.Context) { } func HandleUnDecompressAttachment() { - attachs,err := models.GetUnDecompressAttachments() + attachs, err := models.GetUnDecompressAttachments() if err != nil { log.Error("GetUnDecompressAttachments failed:", err.Error()) return } - for _,attach := range attachs { + for _, attach := range attachs { err = worker.SendDecompressTask(contexExt.Background(), attach.UUID) if err != nil { log.Error("SendDecompressTask(%s) failed:%s", attach.UUID, err.Error())