forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to sync tags from admin dashboard (go-gitea#28045)
Inspired by go-gitea#28043 This PR adds a option to the Admin Dashboard to sync all tags to the database. ![grafik](https://github.com/go-gitea/gitea/assets/15185051/26ac51ef-82a4-4fd9-a6a6-5aefec612ff6)
- Loading branch information
1 parent
50dc9c6
commit 3e511f4
Showing
7 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package release | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/modules/graceful" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/queue" | ||
repo_module "code.gitea.io/gitea/modules/repository" | ||
|
||
"xorm.io/builder" | ||
) | ||
|
||
type TagSyncOptions struct { | ||
RepoID int64 | ||
} | ||
|
||
// tagSyncQueue represents a queue to handle tag sync jobs. | ||
var tagSyncQueue *queue.WorkerPoolQueue[*TagSyncOptions] | ||
|
||
func handlerTagSync(items ...*TagSyncOptions) []*TagSyncOptions { | ||
for _, opts := range items { | ||
err := repo_module.SyncRepoTags(graceful.GetManager().ShutdownContext(), opts.RepoID) | ||
if err != nil { | ||
log.Error("syncRepoTags [%d] failed: %v", opts.RepoID, err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func addRepoToTagSyncQueue(repoID int64) error { | ||
return tagSyncQueue.Push(&TagSyncOptions{ | ||
RepoID: repoID, | ||
}) | ||
} | ||
|
||
func initTagSyncQueue(ctx context.Context) error { | ||
tagSyncQueue = queue.CreateUniqueQueue(ctx, "tag_sync", handlerTagSync) | ||
if tagSyncQueue == nil { | ||
return errors.New("unable to create tag_sync queue") | ||
} | ||
go graceful.GetManager().RunWithCancel(tagSyncQueue) | ||
|
||
return nil | ||
} | ||
|
||
func AddAllRepoTagsToSyncQueue(ctx context.Context) error { | ||
if err := db.Iterate(ctx, builder.Eq{"is_empty": false}, func(ctx context.Context, repo *repo_model.Repository) error { | ||
return addRepoToTagSyncQueue(repo.ID) | ||
}); err != nil { | ||
return fmt.Errorf("run sync all tags failed: %v", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters