Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package release
  4. import (
  5. "context"
  6. "errors"
  7. "fmt"
  8. "code.gitea.io/gitea/models/db"
  9. repo_model "code.gitea.io/gitea/models/repo"
  10. "code.gitea.io/gitea/modules/graceful"
  11. "code.gitea.io/gitea/modules/log"
  12. "code.gitea.io/gitea/modules/queue"
  13. repo_module "code.gitea.io/gitea/modules/repository"
  14. "xorm.io/builder"
  15. )
  16. type TagSyncOptions struct {
  17. RepoID int64
  18. }
  19. // tagSyncQueue represents a queue to handle tag sync jobs.
  20. var tagSyncQueue *queue.WorkerPoolQueue[*TagSyncOptions]
  21. func handlerTagSync(items ...*TagSyncOptions) []*TagSyncOptions {
  22. for _, opts := range items {
  23. err := repo_module.SyncRepoTags(graceful.GetManager().ShutdownContext(), opts.RepoID)
  24. if err != nil {
  25. log.Error("syncRepoTags [%d] failed: %v", opts.RepoID, err)
  26. }
  27. }
  28. return nil
  29. }
  30. func addRepoToTagSyncQueue(repoID int64) error {
  31. return tagSyncQueue.Push(&TagSyncOptions{
  32. RepoID: repoID,
  33. })
  34. }
  35. func initTagSyncQueue(ctx context.Context) error {
  36. tagSyncQueue = queue.CreateUniqueQueue(ctx, "tag_sync", handlerTagSync)
  37. if tagSyncQueue == nil {
  38. return errors.New("unable to create tag_sync queue")
  39. }
  40. go graceful.GetManager().RunWithCancel(tagSyncQueue)
  41. return nil
  42. }
  43. func AddAllRepoTagsToSyncQueue(ctx context.Context) error {
  44. if err := db.Iterate(ctx, builder.Eq{"is_empty": false}, func(ctx context.Context, repo *repo_model.Repository) error {
  45. return addRepoToTagSyncQueue(repo.ID)
  46. }); err != nil {
  47. return fmt.Errorf("run sync all tags failed: %v", err)
  48. }
  49. return nil
  50. }