2020-02-11 15:04:17 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2020-02-11 15:04:17 +05:30
|
|
|
|
|
|
|
package stats
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2020-02-11 15:04:17 +05:30
|
|
|
"code.gitea.io/gitea/modules/graceful"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/queue"
|
|
|
|
)
|
|
|
|
|
|
|
|
// statsQueue represents a queue to handle repository stats updates
|
2020-02-14 18:12:30 +05:30
|
|
|
var statsQueue queue.UniqueQueue
|
2020-02-11 15:04:17 +05:30
|
|
|
|
|
|
|
// handle passed PR IDs and test the PRs
|
2022-01-23 02:52:14 +05:30
|
|
|
func handle(data ...queue.Data) []queue.Data {
|
2020-02-11 15:04:17 +05:30
|
|
|
for _, datum := range data {
|
|
|
|
opts := datum.(int64)
|
|
|
|
if err := indexer.Index(opts); err != nil {
|
2020-08-01 20:15:26 +05:30
|
|
|
log.Error("stats queue indexer.Index(%d) failed: %v", opts, err)
|
2020-02-11 15:04:17 +05:30
|
|
|
}
|
|
|
|
}
|
2022-01-23 02:52:14 +05:30
|
|
|
return nil
|
2020-02-11 15:04:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func initStatsQueue() error {
|
2021-10-18 01:17:12 +05:30
|
|
|
statsQueue = queue.CreateUniqueQueue("repo_stats_update", handle, int64(0))
|
2020-02-11 15:04:17 +05:30
|
|
|
if statsQueue == nil {
|
|
|
|
return fmt.Errorf("Unable to create repo_stats_update Queue")
|
|
|
|
}
|
|
|
|
|
|
|
|
go graceful.GetManager().RunWithShutdownFns(statsQueue.Run)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateRepoIndexer update a repository's entries in the indexer
|
2021-12-10 06:57:50 +05:30
|
|
|
func UpdateRepoIndexer(repo *repo_model.Repository) error {
|
2020-08-01 20:15:26 +05:30
|
|
|
if err := statsQueue.Push(repo.ID); err != nil {
|
|
|
|
if err != queue.ErrAlreadyInQueue {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Debug("Repo ID: %d already queued", repo.ID)
|
|
|
|
}
|
|
|
|
return nil
|
2020-02-11 15:04:17 +05:30
|
|
|
}
|