mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-04 08:17:24 -05:00
bac65f1b82
* Fix incorrect logging in oauth2.go Fix #11945 Signed-off-by: Andrew Thornton <art27@cantab.net> * Handle ErrAlreadyInQueue in stats indexer Fix #12380 Signed-off-by: Andrew Thornton <art27@cantab.net> * Fixes type in error message of indexer Add the missing character in the error message. Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lieven Hollevoet <hollie@lika.be>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package stats
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
"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
|
|
var statsQueue queue.UniqueQueue
|
|
|
|
// handle passed PR IDs and test the PRs
|
|
func handle(data ...queue.Data) {
|
|
for _, datum := range data {
|
|
opts := datum.(int64)
|
|
if err := indexer.Index(opts); err != nil {
|
|
log.Error("stats queue indexer.Index(%d) failed: %v", opts, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func initStatsQueue() error {
|
|
statsQueue = queue.CreateUniqueQueue("repo_stats_update", handle, int64(0)).(queue.UniqueQueue)
|
|
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
|
|
func UpdateRepoIndexer(repo *models.Repository) error {
|
|
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
|
|
}
|