Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

queue.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package stats
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/graceful"
  9. "code.gitea.io/gitea/modules/log"
  10. "code.gitea.io/gitea/modules/queue"
  11. )
  12. // statsQueue represents a queue to handle repository stats updates
  13. var statsQueue queue.UniqueQueue
  14. // handle passed PR IDs and test the PRs
  15. func handle(data ...queue.Data) {
  16. for _, datum := range data {
  17. opts := datum.(int64)
  18. if err := indexer.Index(opts); err != nil {
  19. log.Error("stats queue idexer.Index(%d) failed: %v", opts, err)
  20. }
  21. }
  22. }
  23. func initStatsQueue() error {
  24. statsQueue = queue.CreateUniqueQueue("repo_stats_update", handle, int64(0)).(queue.UniqueQueue)
  25. if statsQueue == nil {
  26. return fmt.Errorf("Unable to create repo_stats_update Queue")
  27. }
  28. go graceful.GetManager().RunWithShutdownFns(statsQueue.Run)
  29. return nil
  30. }
  31. // UpdateRepoIndexer update a repository's entries in the indexer
  32. func UpdateRepoIndexer(repo *models.Repository) error {
  33. return statsQueue.Push(repo.ID)
  34. }