summaryrefslogtreecommitdiffstats
path: root/services/release/tag.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
commitdd136858f1ea40ad3c94191d647487fa4f31926c (patch)
tree58fec94a7b2a12510c9664b21793f1ed560c6518 /services/release/tag.go
parentInitial commit. (diff)
downloadforgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.tar.xz
forgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.zip
Adding upstream version 9.0.0.upstream/9.0.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'services/release/tag.go')
-rw-r--r--services/release/tag.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/services/release/tag.go b/services/release/tag.go
new file mode 100644
index 0000000..dae2b70
--- /dev/null
+++ b/services/release/tag.go
@@ -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
+}