Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaoffical/main'
Browse files Browse the repository at this point in the history
* giteaoffical/main:
  Refactor mirror code & fix `StartToMirror` (go-gitea#18904)
  • Loading branch information
zjjhot committed Mar 2, 2022
2 parents 9a7a780 + a14b6f3 commit 4bbfe03
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions services/mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
}()
}
Expand All @@ -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)
Expand Down

0 comments on commit 4bbfe03

Please # to comment.