1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Move modules/mirror to services (#26737)

To solve the cyclic imports in a better way

Closes #20261
This commit is contained in:
Chongyi Zheng
2023-08-26 22:24:45 -04:00
committed by GitHub
parent 37b3ba22a1
commit 43652746f2
8 changed files with 32 additions and 39 deletions

View File

@@ -10,21 +10,20 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
mirror_module "code.gitea.io/gitea/modules/mirror"
"code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/setting"
)
// doMirrorSync causes this request to mirror itself
func doMirrorSync(ctx context.Context, req *mirror_module.SyncRequest) {
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 mirror_module.PushMirrorType:
case PushMirrorType:
_ = SyncPushMirror(ctx, req.ReferenceID)
case mirror_module.PullMirrorType:
case PullMirrorType:
_ = SyncPullMirror(ctx, req.ReferenceID)
default:
log.Error("Unknown Request type in queue: %v for MirrorID[%d]", req.Type, req.ReferenceID)
@@ -43,7 +42,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
handler := func(idx int, bean any) error {
var repo *repo_model.Repository
var mirrorType mirror_module.SyncType
var mirrorType SyncType
var referenceID int64
if m, ok := bean.(*repo_model.Mirror); ok {
@@ -52,7 +51,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
return nil
}
repo = m.Repo
mirrorType = mirror_module.PullMirrorType
mirrorType = PullMirrorType
referenceID = m.RepoID
} else if m, ok := bean.(*repo_model.PushMirror); ok {
if m.GetRepository() == nil {
@@ -60,7 +59,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
return nil
}
repo = m.Repo
mirrorType = mirror_module.PushMirrorType
mirrorType = PushMirrorType
referenceID = m.ID
} else {
log.Error("Unknown bean: %v", bean)
@@ -75,9 +74,9 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
}
// Push to the Queue
if err := mirror_module.PushToQueue(mirrorType, referenceID); err != nil {
if err := PushToQueue(mirrorType, referenceID); err != nil {
if err == queue.ErrAlreadyInQueue {
if mirrorType == mirror_module.PushMirrorType {
if mirrorType == PushMirrorType {
log.Trace("PushMirrors for %-v already queued for sync", repo)
} else {
log.Trace("PullMirrors for %-v already queued for sync", repo)
@@ -120,7 +119,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
return nil
}
func queueHandler(items ...*mirror_module.SyncRequest) []*mirror_module.SyncRequest {
func queueHandler(items ...*SyncRequest) []*SyncRequest {
for _, req := range items {
doMirrorSync(graceful.GetManager().ShutdownContext(), req)
}
@@ -129,5 +128,5 @@ func queueHandler(items ...*mirror_module.SyncRequest) []*mirror_module.SyncRequ
// InitSyncMirrors initializes a go routine to sync the mirrors
func InitSyncMirrors() {
mirror_module.StartSyncMirrors(queueHandler)
StartSyncMirrors(queueHandler)
}