diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-03-02 07:43:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-02 15:43:11 +0800 |
commit | a14b6f3aae196b2506e07f1dcfcd38d338b91e68 (patch) | |
tree | 5d3315fd9e2568af4ca46762737547587edfdcff | |
parent | a90041d71aa1ee3c0e4040c42ebc7ff488220802 (diff) | |
download | gitea-a14b6f3aae196b2506e07f1dcfcd38d338b91e68.tar.gz gitea-a14b6f3aae196b2506e07f1dcfcd38d338b91e68.zip |
Refactor mirror code & fix `StartToMirror` (#18904)
* Use MirrorID instead of RepoID
- Use the MirrorID as index(SQL uses `id` column not the `repo_id`).
Passes the Mirror ID's into the Sync functions.
* Check for MirrorID == 0
* Fix `StartToMirror` + refactor
* Update services/mirror/mirror.go
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r-- | services/mirror/mirror.go | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/services/mirror/mirror.go b/services/mirror/mirror.go index ed3a878d01..edc5a84d22 100644 --- a/services/mirror/mirror.go +++ b/services/mirror/mirror.go @@ -29,19 +29,23 @@ const ( // SyncRequest for the mirror queue type SyncRequest struct { - Type SyncType - RepoID int64 + Type SyncType + ReferenceID int64 // RepoID for pull mirror, MirrorID fro push mirror } // doMirrorSync causes this request to mirror itself func doMirrorSync(ctx context.Context, req *SyncRequest) { + if req.ReferenceID == 0 { + log.Warn("Skipping mirror sync request, no mirror ID was specified") + return + } switch req.Type { case PushMirrorType: - _ = SyncPushMirror(ctx, req.RepoID) + _ = SyncPushMirror(ctx, req.ReferenceID) case PullMirrorType: - _ = SyncPullMirror(ctx, req.RepoID) + _ = SyncPullMirror(ctx, req.ReferenceID) default: - log.Error("Unknown Request type in queue: %v for RepoID[%d]", req.Type, req.RepoID) + log.Error("Unknown Request type in queue: %v for MirrorID[%d]", req.Type, req.ReferenceID) } } @@ -65,8 +69,8 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error { } repo = m.Repo item = SyncRequest{ - Type: PullMirrorType, - RepoID: m.RepoID, + Type: PullMirrorType, + ReferenceID: m.RepoID, } } else if m, ok := bean.(*repo_model.PushMirror); ok { if m.Repo == nil { @@ -75,8 +79,8 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error { } repo = m.Repo item = SyncRequest{ - Type: PushMirrorType, - RepoID: m.RepoID, + Type: PushMirrorType, + ReferenceID: m.ID, } } else { log.Error("Unknown bean: %v", bean) @@ -161,11 +165,12 @@ func StartToMirror(repoID int64) { } go func() { err := mirrorQueue.Push(&SyncRequest{ - Type: PullMirrorType, - RepoID: repoID, + Type: PullMirrorType, + ReferenceID: repoID, }) if err != nil { - log.Error("Unable to push sync request for to the queue for push mirror repo[%d]: Error: %v", repoID, err) + log.Error("Unable to push sync request for to the queue for pull mirror repo[%d]: Error: %v", repoID, err) + return } }() } @@ -177,8 +182,8 @@ func AddPushMirrorToQueue(mirrorID int64) { } go func() { err := mirrorQueue.Push(&SyncRequest{ - Type: PushMirrorType, - RepoID: mirrorID, + Type: PushMirrorType, + ReferenceID: mirrorID, }) if err != nil { log.Error("Unable to push sync request to the queue for pull mirror repo[%d]: Error: %v", mirrorID, err) |