From fc68fb951c179b125b37a83f9e0b5f8dde0478f8 Mon Sep 17 00:00:00 2001 From: Thibault Meyer <0xbaadf00d@users.noreply.github.com> Date: Wed, 10 Aug 2016 08:47:16 +0200 Subject: [PATCH] Feature #3398: Redefine global mirror interval (#3409) * add mirror::GLOBAL_INTERVAL on app.ini * rename key to DEFAULT_INTERVAL * add key on default app.ini + move code --- conf/app.ini | 4 ++++ models/repo.go | 4 ++-- modules/setting/setting.go | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index 006b260be1..5b46365cb9 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -359,6 +359,10 @@ CLONE = 300 PULL = 300 GC = 60 +[mirror] +; Default interval in hours between each check +DEFAULT_INTERVAL = 24 + [api] ; Max number of items will response in a page MAX_RESPONSE_ITEMS = 50 diff --git a/models/repo.go b/models/repo.go index 92755e9e43..822ad1d9ca 100644 --- a/models/repo.go +++ b/models/repo.go @@ -724,9 +724,9 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) { if opts.IsMirror { if _, err = x.InsertOne(&Mirror{ RepoID: repo.ID, - Interval: 24, + Interval: setting.Mirror.DefaultInterval, EnablePrune: true, - NextUpdate: time.Now().Add(24 * time.Hour), + NextUpdate: time.Now().Add(time.Duration(setting.Mirror.DefaultInterval) * time.Hour), }); err != nil { return repo, fmt.Errorf("InsertOne: %v", err) } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index a56c4824e9..787e2c81b0 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -208,6 +208,10 @@ var ( } `ini:"git.timeout"` } + Mirror struct { + DefaultInterval int + } + // API settings API struct { MaxResponseItems int @@ -514,6 +518,12 @@ func NewContext() { log.Fatal(4, "Fail to map Git settings: %v", err) } else if err = Cfg.Section("api").MapTo(&API); err != nil { log.Fatal(4, "Fail to map API settings: %v", err) + } else if err = Cfg.Section("mirror").MapTo(&Mirror); err != nil { + log.Fatal(4, "Fail to map API settings: %v", err) + } + + if Mirror.DefaultInterval <= 0 { + Mirror.DefaultInterval = 24 } Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")