Browse Source

Merge branch 'develop' into dev-chunk

tags/v1.21.12.1
palytoxin 5 years ago
parent
commit
6029abbee9
12 changed files with 45 additions and 76 deletions
  1. +2
    -0
      custom/conf/app.ini.sample
  2. +0
    -1
      main.go
  3. +13
    -13
      models/attachment.go
  4. +0
    -1
      models/migrations/migrations.go
  5. +0
    -35
      models/migrations/v140.go
  6. +7
    -0
      modules/decompression/decompression.go
  7. +3
    -3
      modules/setting/setting.go
  8. +3
    -3
      modules/timer/timer.go
  9. +3
    -3
      modules/worker/task.go
  10. +8
    -13
      modules/worker/worker.go
  11. +2
    -0
      routers/init.go
  12. +4
    -4
      routers/repo/attachment.go

+ 2
- 0
custom/conf/app.ini.sample View File

@@ -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


+ 0
- 1
main.go View File

@@ -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"
)


+ 13
- 13
models/attachment.go View File

@@ -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() {


+ 0
- 1
models/migrations/migrations.go View File

@@ -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


+ 0
- 35
models/migrations/v140.go View File

@@ -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
}

+ 7
- 0
modules/decompression/decompression.go View File

@@ -0,0 +1,7 @@
package decompression

import "code.gitea.io/gitea/modules/worker"

func NewContext() {
worker.NewTaskCenter()
}

+ 3
- 3
modules/setting/setting.go View File

@@ -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.


+ 3
- 3
modules/timer/timer.go View File

@@ -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()
}
} ()
}()
}

+ 3
- 3
modules/worker/task.go View File

@@ -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


+ 8
- 13
modules/worker/worker.go View File

@@ -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)
}


+ 2
- 0
routers/init.go View File

@@ -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


+ 4
- 4
routers/repo/attachment.go View File

@@ -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())


Loading…
Cancel
Save