From 7ede275e400230203879d5348243ceefe3fffa60 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Tue, 18 Aug 2020 15:02:58 +0800 Subject: [PATCH 1/4] fix 51 --- custom/conf/app.ini.sample | 2 ++ main.go | 1 - modules/worker/worker.go | 2 +- routers/init.go | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) mode change 100644 => 100755 routers/init.go 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/modules/worker/worker.go b/modules/worker/worker.go index 25bf0cb4c..ab44d2472 100755 --- a/modules/worker/worker.go +++ b/modules/worker/worker.go @@ -10,7 +10,7 @@ var ( AsyncTaskCenter *machinery.Server ) -func init() { +func Init() { tc, err := NewTaskCenter() if err != nil { panic(err) diff --git a/routers/init.go b/routers/init.go old mode 100644 new mode 100755 index f899e8ad9..c2b6da92a --- a/routers/init.go +++ b/routers/init.go @@ -31,6 +31,7 @@ import ( "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/task" "code.gitea.io/gitea/modules/webhook" + "code.gitea.io/gitea/modules/worker" "code.gitea.io/gitea/services/mailer" mirror_service "code.gitea.io/gitea/services/mirror" pull_service "code.gitea.io/gitea/services/pull" @@ -61,6 +62,7 @@ func NewServices() { mailer.NewContext() _ = cache.NewContext() notification.NewContext() + worker.Init() } // In case of problems connecting to DB, retry connection. Eg, PGSQL in Docker Container on Synology From aae0fbe1a1427d8edb21c1c648d25d853eb989a6 Mon Sep 17 00:00:00 2001 From: palytoxin Date: Tue, 18 Aug 2020 17:32:23 +0800 Subject: [PATCH 2/4] improve struct --- .tool-versions | 1 - modules/decompression/decompression.go | 7 +++++++ modules/setting/setting.go | 6 +++--- modules/worker/task.go | 6 +++--- modules/worker/worker.go | 18 ++++++------------ routers/init.go | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) delete mode 100644 .tool-versions create mode 100644 modules/decompression/decompression.go diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index ad70fcacb..000000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -nodejs 12.14.0 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/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 ab44d2472..37445c978 100755 --- a/modules/worker/worker.go +++ b/modules/worker/worker.go @@ -10,21 +10,15 @@ var ( AsyncTaskCenter *machinery.Server ) -func Init() { - tc, err := NewTaskCenter() - if err != nil { - panic(err) - } - AsyncTaskCenter = tc -} - -func NewTaskCenter() (*machinery.Server, error) { +func NewTaskCenter() { cnf := &mchConf.Config{ Broker: setting.Broker, DefaultQueue: setting.DefaultQueue, ResultBackend: setting.ResultBackend, } - // Create server instance - return machinery.NewServer(cnf) + tc, err := machinery.NewServer(cnf) + if err != nil { + panic(err) + } + AsyncTaskCenter = tc } - diff --git a/routers/init.go b/routers/init.go index c2b6da92a..dafe0a202 100755 --- 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" @@ -31,7 +32,6 @@ import ( "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/task" "code.gitea.io/gitea/modules/webhook" - "code.gitea.io/gitea/modules/worker" "code.gitea.io/gitea/services/mailer" mirror_service "code.gitea.io/gitea/services/mirror" pull_service "code.gitea.io/gitea/services/pull" @@ -62,7 +62,7 @@ func NewServices() { mailer.NewContext() _ = cache.NewContext() notification.NewContext() - worker.Init() + decompression.NewContext() } // In case of problems connecting to DB, retry connection. Eg, PGSQL in Docker Container on Synology From f40dcaa5dee8e6361a28bf24bab1eef149b3a974 Mon Sep 17 00:00:00 2001 From: palytoxin Date: Tue, 18 Aug 2020 18:15:34 +0800 Subject: [PATCH 3/4] fmt-check --- models/attachment.go | 26 +++++++++++++------------- modules/timer/timer.go | 6 +++--- routers/repo/attachment.go | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) 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/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/routers/repo/attachment.go b/routers/repo/attachment.go index f40783bc2..5f69d70ba 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -24,8 +24,8 @@ import ( const ( //result of decompress - DecompressSuccess = "0" - DecompressFailed = "1" + DecompressSuccess = "0" + DecompressFailed = "1" ) func RenderAttachmentSettings(ctx *context.Context) { @@ -330,13 +330,13 @@ func UpdateAttachmentDecompressState(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()) From 3e48e99c87d1956903bfb5ac344f1a7e9f9245ed Mon Sep 17 00:00:00 2001 From: palytoxin Date: Wed, 19 Aug 2020 09:38:09 +0800 Subject: [PATCH 4/4] remove duplicate migration --- models/migrations/migrations.go | 1 - models/migrations/v140.go | 35 --------------------------------- 2 files changed, 36 deletions(-) delete mode 100644 models/migrations/v140.go 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 -}