From 295d2512325210d6a1a5251ac999a93a4de10c8a Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 8 Mar 2017 17:47:44 -0500 Subject: [PATCH] mirror: update repository updated_unix after sync (#2807) --- gogs.go | 2 +- models/mirror.go | 29 +++++++++++++++++------------ modules/httplib/httplib.go | 2 +- templates/.VERSION | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/gogs.go b/gogs.go index 708db4103..633776b65 100644 --- a/gogs.go +++ b/gogs.go @@ -16,7 +16,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.10.8.0308" +const APP_VER = "0.10.9.0308" func init() { setting.AppVer = APP_VER diff --git a/models/mirror.go b/models/mirror.go index 722d769fa..a1c14e04e 100644 --- a/models/mirror.go +++ b/models/mirror.go @@ -55,7 +55,7 @@ func (m *Mirror) AfterSet(colName string, _ xorm.Cell) { case "repo_id": m.Repo, err = GetRepositoryByID(m.RepoID) if err != nil { - log.Error(3, "GetRepositoryByID[%d]: %v", m.ID, err) + log.Error(3, "GetRepositoryByID [%d]: %v", m.ID, err) } case "updated_unix": m.Updated = time.Unix(m.UpdatedUnix, 0).Local() @@ -76,7 +76,7 @@ func (m *Mirror) readAddress() { cfg, err := ini.Load(m.Repo.GitConfigPath()) if err != nil { - log.Error(4, "Load: %v", err) + log.Error(2, "Load: %v", err) return } m.address = cfg.Section("remote \"origin\"").Key("url").Value() @@ -142,9 +142,9 @@ func (m *Mirror) runSync() bool { URL: m.FullAddress(), Timeout: 10 * time.Second, }) { - desc := fmt.Sprintf("Mirror repository URL is not accessible: %s", m.MosaicsAddress()) + desc := fmt.Sprintf("Source URL of mirror repository '%s' is not accessible: %s", m.Repo.FullName(), m.MosaicsAddress()) if err := CreateRepositoryNotice(desc); err != nil { - log.Error(4, "CreateRepositoryNotice: %v", err) + log.Error(2, "CreateRepositoryNotice: %v", err) } return false } @@ -157,9 +157,9 @@ func (m *Mirror) runSync() bool { timeout, repoPath, fmt.Sprintf("Mirror.runSync: %s", repoPath), "git", gitArgs...); err != nil { desc := fmt.Sprintf("Fail to update mirror repository '%s': %s", repoPath, stderr) - log.Error(4, desc) + log.Error(2, desc) if err = CreateRepositoryNotice(desc); err != nil { - log.Error(4, "CreateRepositoryNotice: %v", err) + log.Error(2, "CreateRepositoryNotice: %v", err) } return false } @@ -168,9 +168,9 @@ func (m *Mirror) runSync() bool { timeout, wikiPath, fmt.Sprintf("Mirror.runSync: %s", wikiPath), "git", "remote", "update", "--prune"); err != nil { desc := fmt.Sprintf("Fail to update mirror wiki repository '%s': %s", wikiPath, stderr) - log.Error(4, desc) + log.Error(2, desc) if err = CreateRepositoryNotice(desc); err != nil { - log.Error(4, "CreateRepositoryNotice: %v", err) + log.Error(2, "CreateRepositoryNotice: %v", err) } return false } @@ -222,14 +222,14 @@ func MirrorUpdate() { if err := x.Where("next_update_unix<=?", time.Now().Unix()).Iterate(new(Mirror), func(idx int, bean interface{}) error { m := bean.(*Mirror) if m.Repo == nil { - log.Error(4, "Disconnected mirror repository found: %d", m.ID) + log.Error(2, "Disconnected mirror repository found: %d", m.ID) return nil } MirrorQueue.Add(m.RepoID) return nil }); err != nil { - log.Error(4, "MirrorUpdate: %v", err) + log.Error(2, "MirrorUpdate: %v", err) } } @@ -243,7 +243,7 @@ func SyncMirrors() { m, err := GetMirrorByRepoID(com.StrTo(repoID).MustInt64()) if err != nil { - log.Error(4, "GetMirrorByRepoID [%s]: %v", repoID, err) + log.Error(2, "GetMirrorByRepoID [%s]: %v", m.RepoID, err) continue } @@ -253,9 +253,14 @@ func SyncMirrors() { m.ScheduleNextUpdate() if err = UpdateMirror(m); err != nil { - log.Error(4, "UpdateMirror [%s]: %v", repoID, err) + log.Error(2, "UpdateMirror [%s]: %v", m.RepoID, err) continue } + + // Update repository last updated time + if _, err = x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", time.Now().Unix(), m.RepoID); err != nil { + log.Error(2, "Update repository 'updated_unix' [%s]: %v", m.RepoID, err) + } } } diff --git a/modules/httplib/httplib.go b/modules/httplib/httplib.go index ff03195c8..deca5db59 100644 --- a/modules/httplib/httplib.go +++ b/modules/httplib/httplib.go @@ -139,7 +139,7 @@ func (r *Request) Debug(isdebug bool) *Request { return r } -// SetTimeout sets connect time out and read-write time out for BeegoRequest. +// SetTimeout sets connect time out and read-write time out for Request. func (r *Request) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *Request { r.setting.ConnectTimeout = connectTimeout r.setting.ReadWriteTimeout = readWriteTimeout diff --git a/templates/.VERSION b/templates/.VERSION index 236a5ac46..8c94423ed 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.10.8.0308 \ No newline at end of file +0.10.9.0308 \ No newline at end of file