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