aboutsummaryrefslogtreecommitdiffstats
path: root/modules/setting
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-10-17 12:43:25 +0100
committerGitHub <noreply@github.com>2021-10-17 12:43:25 +0100
commit7117c7774ae1c1003c95d3df8dfaa5bd7270165d (patch)
treeeab8f310ad065af318a5c4dedb7efdb6251436cb /modules/setting
parentb9a2f263b8a4c19b01f3440b52f0f90f3c1ee072 (diff)
downloadgitea-7117c7774ae1c1003c95d3df8dfaa5bd7270165d.tar.gz
gitea-7117c7774ae1c1003c95d3df8dfaa5bd7270165d.zip
Make the Mirror Queue a queue (#17326)
Convert the old mirror syncing queue to the more modern queue format. Fix a bug in the from the repo-archive queue PR - the assumption was made that uniqueness could be enforced with by checking equality in a map in channel unique queues - however this only works for primitive types - which was the initial intention but is an imperfect. This is fixed by marshalling the data and placing the martialled data in the unique map instead. The documentation is also updated to add information about the deprecated configuration values. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/setting')
-rw-r--r--modules/setting/mailer.go2
-rw-r--r--modules/setting/queue.go64
-rw-r--r--modules/setting/repository.go4
3 files changed, 39 insertions, 31 deletions
diff --git a/modules/setting/mailer.go b/modules/setting/mailer.go
index a2228e938b..d2fac440ac 100644
--- a/modules/setting/mailer.go
+++ b/modules/setting/mailer.go
@@ -16,7 +16,6 @@ import (
// Mailer represents mail service.
type Mailer struct {
// Mailer
- QueueLength int
Name string
From string
FromName string
@@ -54,7 +53,6 @@ func newMailService() {
}
MailService = &Mailer{
- QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
Name: sec.Key("NAME").MustString(AppName),
SendAsPlainText: sec.Key("SEND_AS_PLAIN_TEXT").MustBool(false),
MailerType: sec.Key("MAILER_TYPE").In("", []string{"smtp", "sendmail", "dummy"}),
diff --git a/modules/setting/queue.go b/modules/setting/queue.go
index 76b7dc1faf..1668cc63a3 100644
--- a/modules/setting/queue.go
+++ b/modules/setting/queue.go
@@ -5,11 +5,12 @@
package setting
import (
- "fmt"
"path/filepath"
+ "strconv"
"time"
"code.gitea.io/gitea/modules/log"
+ ini "gopkg.in/ini.v1"
)
// QueueSettings represent the settings for a queue from the ini
@@ -106,11 +107,8 @@ func NewQueueService() {
// Now handle the old issue_indexer configuration
section := Cfg.Section("queue.issue_indexer")
- sectionMap := map[string]bool{}
- for _, key := range section.Keys() {
- sectionMap[key.Name()] = true
- }
- if _, ok := sectionMap["TYPE"]; !ok && defaultType == "" {
+ directlySet := toDirectlySetKeysMap(section)
+ if !directlySet["TYPE"] && defaultType == "" {
switch Indexer.IssueQueueType {
case LevelQueueType:
_, _ = section.NewKey("TYPE", "level")
@@ -125,37 +123,53 @@ func NewQueueService() {
Indexer.IssueQueueType)
}
}
- if _, ok := sectionMap["LENGTH"]; !ok && Indexer.UpdateQueueLength != 0 {
- _, _ = section.NewKey("LENGTH", fmt.Sprintf("%d", Indexer.UpdateQueueLength))
+ if !directlySet["LENGTH"] && Indexer.UpdateQueueLength != 0 {
+ _, _ = section.NewKey("LENGTH", strconv.Itoa(Indexer.UpdateQueueLength))
}
- if _, ok := sectionMap["BATCH_LENGTH"]; !ok && Indexer.IssueQueueBatchNumber != 0 {
- _, _ = section.NewKey("BATCH_LENGTH", fmt.Sprintf("%d", Indexer.IssueQueueBatchNumber))
+ if !directlySet["BATCH_LENGTH"] && Indexer.IssueQueueBatchNumber != 0 {
+ _, _ = section.NewKey("BATCH_LENGTH", strconv.Itoa(Indexer.IssueQueueBatchNumber))
}
- if _, ok := sectionMap["DATADIR"]; !ok && Indexer.IssueQueueDir != "" {
+ if !directlySet["DATADIR"] && Indexer.IssueQueueDir != "" {
_, _ = section.NewKey("DATADIR", Indexer.IssueQueueDir)
}
- if _, ok := sectionMap["CONN_STR"]; !ok && Indexer.IssueQueueConnStr != "" {
+ if !directlySet["CONN_STR"] && Indexer.IssueQueueConnStr != "" {
_, _ = section.NewKey("CONN_STR", Indexer.IssueQueueConnStr)
}
// Handle the old mailer configuration
- section = Cfg.Section("queue.mailer")
- sectionMap = map[string]bool{}
- for _, key := range section.Keys() {
- sectionMap[key.Name()] = true
- }
- if _, ok := sectionMap["LENGTH"]; !ok {
- _, _ = section.NewKey("LENGTH", fmt.Sprintf("%d", Cfg.Section("mailer").Key("SEND_BUFFER_LEN").MustInt(100)))
- }
+ handleOldLengthConfiguration("mailer", Cfg.Section("mailer").Key("SEND_BUFFER_LEN").MustInt(100))
// Handle the old test pull requests configuration
// Please note this will be a unique queue
- section = Cfg.Section("queue.pr_patch_checker")
- sectionMap = map[string]bool{}
+ handleOldLengthConfiguration("pr_patch_checker", Cfg.Section("repository").Key("PULL_REQUEST_QUEUE_LENGTH").MustInt(1000))
+
+ // Handle the old mirror queue configuration
+ // Please note this will be a unique queue
+ handleOldLengthConfiguration("mirror", Cfg.Section("repository").Key("MIRROR_QUEUE_LENGTH").MustInt(1000))
+}
+
+// handleOldLengthConfiguration allows fallback to older configuration. `[queue.name]` `LENGTH` will override this configuration, but
+// if that is left unset then we should fallback to the older configuration. (Except where the new length woul be <=0)
+func handleOldLengthConfiguration(queueName string, value int) {
+ // Don't override with 0
+ if value <= 0 {
+ return
+ }
+
+ section := Cfg.Section("queue." + queueName)
+ directlySet := toDirectlySetKeysMap(section)
+ if !directlySet["LENGTH"] {
+ _, _ = section.NewKey("LENGTH", strconv.Itoa(value))
+ }
+}
+
+// toDirectlySetKeysMap returns a bool map of keys directly set by this section
+// Note: we cannot use section.HasKey(...) as that will immediately set the Key if a parent section has the Key
+// but this section does not.
+func toDirectlySetKeysMap(section *ini.Section) map[string]bool {
+ sectionMap := map[string]bool{}
for _, key := range section.Keys() {
sectionMap[key.Name()] = true
}
- if _, ok := sectionMap["LENGTH"]; !ok {
- _, _ = section.NewKey("LENGTH", fmt.Sprintf("%d", Repository.PullRequestQueueLength))
- }
+ return sectionMap
}
diff --git a/modules/setting/repository.go b/modules/setting/repository.go
index de57eb9140..0791602efb 100644
--- a/modules/setting/repository.go
+++ b/modules/setting/repository.go
@@ -29,8 +29,6 @@ var (
DefaultPrivate string
DefaultPushCreatePrivate bool
MaxCreationLimit int
- MirrorQueueLength int
- PullRequestQueueLength int
PreferredLicenses []string
DisableHTTPGit bool
AccessControlAllowOrigin string
@@ -142,8 +140,6 @@ var (
DefaultPrivate: RepoCreatingLastUserVisibility,
DefaultPushCreatePrivate: true,
MaxCreationLimit: -1,
- MirrorQueueLength: 1000,
- PullRequestQueueLength: 1000,
PreferredLicenses: []string{"Apache License 2.0", "MIT License"},
DisableHTTPGit: false,
AccessControlAllowOrigin: "",