Files
gitea/modules/indexer/stats/queue.go
T
zeripath a82fd98d53 Pause queues (#15928)
* Start adding mechanism to return unhandled data

Signed-off-by: Andrew Thornton <[email protected]>

* Create pushback interface

Signed-off-by: Andrew Thornton <[email protected]>

* Add Pausable interface to WorkerPool and Manager

Signed-off-by: Andrew Thornton <[email protected]>

* Implement Pausable and PushBack for the bytefifos

Signed-off-by: Andrew Thornton <[email protected]>

* Implement Pausable and Pushback for ChannelQueues and ChannelUniqueQueues

Signed-off-by: Andrew Thornton <[email protected]>

* Wire in UI for pausing

Signed-off-by: Andrew Thornton <[email protected]>

* add testcases and fix a few issues

Signed-off-by: Andrew Thornton <[email protected]>

* fix build

Signed-off-by: Andrew Thornton <[email protected]>

* prevent "race" in the test

Signed-off-by: Andrew Thornton <[email protected]>

* fix jsoniter mismerge

Signed-off-by: Andrew Thornton <[email protected]>

* fix conflicts

Signed-off-by: Andrew Thornton <[email protected]>

* fix format

Signed-off-by: Andrew Thornton <[email protected]>

* Add warnings for no worker configurations and prevent data-loss with redis/levelqueue

Signed-off-by: Andrew Thornton <[email protected]>

* Use StopTimer

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: Lauris BH <[email protected]>
Co-authored-by: 6543 <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
Co-authored-by: wxiaoguang <[email protected]>
2022-01-22 21:22:14 +00:00

51 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"
repo_model "code.gitea.io/gitea/models/repo"
"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) []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)
}
}
return nil
}
func initStatsQueue() error {
statsQueue = queue.CreateUniqueQueue("repo_stats_update", handle, int64(0))
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 *repo_model.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
}