Reviewed-by: palytoxin <sxty32@126.com>tags/v1.21.12.1
| @@ -1 +0,0 @@ | |||||
| nodejs 12.14.0 | |||||
| @@ -753,6 +753,8 @@ MINIO_LOCATION = us-east-1 | |||||
| MINIO_BASE_PATH = attachments/ | MINIO_BASE_PATH = attachments/ | ||||
| ; Minio enabled ssl only available when STORE_TYPE is `minio` | ; Minio enabled ssl only available when STORE_TYPE is `minio` | ||||
| MINIO_USE_SSL = false | MINIO_USE_SSL = false | ||||
| ; real Minio storage path | |||||
| MINIO_REAL_PATH = /mnt/test/minio/data/ | |||||
| [time] | [time] | ||||
| ; Specifies the format for fully outputted dates. Defaults to RFC1123 | ; Specifies the format for fully outputted dates. Defaults to RFC1123 | ||||
| @@ -22,7 +22,6 @@ import ( | |||||
| _ "code.gitea.io/gitea/modules/markup/markdown" | _ "code.gitea.io/gitea/modules/markup/markdown" | ||||
| _ "code.gitea.io/gitea/modules/markup/orgmode" | _ "code.gitea.io/gitea/modules/markup/orgmode" | ||||
| _ "code.gitea.io/gitea/modules/timer" | _ "code.gitea.io/gitea/modules/timer" | ||||
| _ "code.gitea.io/gitea/modules/worker" | |||||
| "github.com/urfave/cli" | "github.com/urfave/cli" | ||||
| ) | ) | ||||
| @@ -28,19 +28,19 @@ const ( | |||||
| // Attachment represent a attachment of issue/comment/release. | // Attachment represent a attachment of issue/comment/release. | ||||
| type Attachment struct { | 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() { | func (a *Attachment) AfterUpdate() { | ||||
| @@ -212,7 +212,6 @@ var migrations = []Migration{ | |||||
| NewMigration("Add ResolveDoerID to Comment table", addResolveDoerIDCommentColumn), | NewMigration("Add ResolveDoerID to Comment table", addResolveDoerIDCommentColumn), | ||||
| // v139 -> v140 | // v139 -> v140 | ||||
| NewMigration("prepend refs/heads/ to issue refs", prependRefsHeadsToIssueRefs), | NewMigration("prepend refs/heads/ to issue refs", prependRefsHeadsToIssueRefs), | ||||
| NewMigration("add dataset migration", addDatasetTable), | |||||
| } | } | ||||
| // GetCurrentDBVersion returns the current db version | // GetCurrentDBVersion returns the current db version | ||||
| @@ -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 | |||||
| } | |||||
| @@ -0,0 +1,7 @@ | |||||
| package decompression | |||||
| import "code.gitea.io/gitea/modules/worker" | |||||
| func NewContext() { | |||||
| worker.NewTaskCenter() | |||||
| } | |||||
| @@ -420,9 +420,9 @@ var ( | |||||
| UILocation = time.Local | UILocation = time.Local | ||||
| //Machinery config | //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. | // DateLang transforms standard language locale name to corresponding value in datetime plugin. | ||||
| @@ -7,15 +7,15 @@ import ( | |||||
| ) | ) | ||||
| const ( | const ( | ||||
| DecompressTimer = time.Minute * 10 | |||||
| DecompressTimer = time.Minute * 10 | |||||
| ) | ) | ||||
| func init() { | func init() { | ||||
| ticker := time.NewTicker(DecompressTimer) | ticker := time.NewTicker(DecompressTimer) | ||||
| go func() { | go func() { | ||||
| for { | for { | ||||
| <- ticker.C | |||||
| <-ticker.C | |||||
| repo.HandleUnDecompressAttachment() | repo.HandleUnDecompressAttachment() | ||||
| } | } | ||||
| } () | |||||
| }() | |||||
| } | } | ||||
| @@ -10,10 +10,10 @@ import ( | |||||
| // 方法名 | // 方法名 | ||||
| const ( | 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}} | args := []tasks.Arg{{Name: "uuid", Type: "string", Value: uuid}} | ||||
| task, err := tasks.NewSignature(DecompressTaskName, args) | task, err := tasks.NewSignature(DecompressTaskName, args) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -22,7 +22,7 @@ func SendDecompressTask(ctx context.Context, uuid string) error{ | |||||
| } | } | ||||
| task.RetryCount = 3 | task.RetryCount = 3 | ||||
| _,err = AsyncTaskCenter.SendTaskWithContext(ctx, task) | |||||
| _, err = AsyncTaskCenter.SendTaskWithContext(ctx, task) | |||||
| if err != nil { | if err != nil { | ||||
| log.Error("SendTaskWithContext failed:", err.Error()) | log.Error("SendTaskWithContext failed:", err.Error()) | ||||
| return err | return err | ||||
| @@ -10,21 +10,15 @@ var ( | |||||
| AsyncTaskCenter *machinery.Server | 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{ | cnf := &mchConf.Config{ | ||||
| Broker: setting.Broker, | Broker: setting.Broker, | ||||
| DefaultQueue: setting.DefaultQueue, | DefaultQueue: setting.DefaultQueue, | ||||
| ResultBackend: setting.ResultBackend, | ResultBackend: setting.ResultBackend, | ||||
| } | } | ||||
| // Create server instance | |||||
| return machinery.NewServer(cnf) | |||||
| tc, err := machinery.NewServer(cnf) | |||||
| if err != nil { | |||||
| panic(err) | |||||
| } | |||||
| AsyncTaskCenter = tc | |||||
| } | } | ||||
| @@ -15,6 +15,7 @@ import ( | |||||
| "code.gitea.io/gitea/modules/auth/sso" | "code.gitea.io/gitea/modules/auth/sso" | ||||
| "code.gitea.io/gitea/modules/cache" | "code.gitea.io/gitea/modules/cache" | ||||
| "code.gitea.io/gitea/modules/cron" | "code.gitea.io/gitea/modules/cron" | ||||
| "code.gitea.io/gitea/modules/decompression" | |||||
| "code.gitea.io/gitea/modules/eventsource" | "code.gitea.io/gitea/modules/eventsource" | ||||
| "code.gitea.io/gitea/modules/git" | "code.gitea.io/gitea/modules/git" | ||||
| "code.gitea.io/gitea/modules/highlight" | "code.gitea.io/gitea/modules/highlight" | ||||
| @@ -61,6 +62,7 @@ func NewServices() { | |||||
| mailer.NewContext() | mailer.NewContext() | ||||
| _ = cache.NewContext() | _ = cache.NewContext() | ||||
| notification.NewContext() | notification.NewContext() | ||||
| decompression.NewContext() | |||||
| } | } | ||||
| // In case of problems connecting to DB, retry connection. Eg, PGSQL in Docker Container on Synology | // In case of problems connecting to DB, retry connection. Eg, PGSQL in Docker Container on Synology | ||||
| @@ -24,8 +24,8 @@ import ( | |||||
| const ( | const ( | ||||
| //result of decompress | //result of decompress | ||||
| DecompressSuccess = "0" | |||||
| DecompressFailed = "1" | |||||
| DecompressSuccess = "0" | |||||
| DecompressFailed = "1" | |||||
| ) | ) | ||||
| func RenderAttachmentSettings(ctx *context.Context) { | func RenderAttachmentSettings(ctx *context.Context) { | ||||
| @@ -330,13 +330,13 @@ func UpdateAttachmentDecompressState(ctx *context.Context) { | |||||
| } | } | ||||
| func HandleUnDecompressAttachment() { | func HandleUnDecompressAttachment() { | ||||
| attachs,err := models.GetUnDecompressAttachments() | |||||
| attachs, err := models.GetUnDecompressAttachments() | |||||
| if err != nil { | if err != nil { | ||||
| log.Error("GetUnDecompressAttachments failed:", err.Error()) | log.Error("GetUnDecompressAttachments failed:", err.Error()) | ||||
| return | return | ||||
| } | } | ||||
| for _,attach := range attachs { | |||||
| for _, attach := range attachs { | |||||
| err = worker.SendDecompressTask(contexExt.Background(), attach.UUID) | err = worker.SendDecompressTask(contexExt.Background(), attach.UUID) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("SendDecompressTask(%s) failed:%s", attach.UUID, err.Error()) | log.Error("SendDecompressTask(%s) failed:%s", attach.UUID, err.Error()) | ||||