ad2642a8aa
* Implementation for calculating language statistics Impement saving code language statistics to database Implement rendering langauge stats Add primary laguage to show in repository list Implement repository stats indexer queue Add indexer test Refactor to use queue module * Do not timeout for queues
44 lines
1.1 KiB
Go
44 lines
1.1 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.Queue
|
|
|
|
// 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 idexer.Index(%d) failed: %v", opts, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func initStatsQueue() error {
|
|
statsQueue = queue.CreateQueue("repo_stats_update", handle, int64(0)).(queue.Queue)
|
|
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 {
|
|
return statsQueue.Push(repo.ID)
|
|
}
|