mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	Automatically pause queue if index service is unavailable (#15066)
* Handle keyword search error when issue indexer service is not available * Implement automatic disabling and resume of code indexer queue
This commit is contained in:
		@@ -4,33 +4,47 @@
 | 
			
		||||
 | 
			
		||||
package issues
 | 
			
		||||
 | 
			
		||||
import "code.gitea.io/gitea/models"
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/models"
 | 
			
		||||
	"code.gitea.io/gitea/models/db"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// DBIndexer implements Indexer interface to use database's like search
 | 
			
		||||
type DBIndexer struct{}
 | 
			
		||||
 | 
			
		||||
// Init dummy function
 | 
			
		||||
func (db *DBIndexer) Init() (bool, error) {
 | 
			
		||||
func (i *DBIndexer) Init() (bool, error) {
 | 
			
		||||
	return false, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetAvailabilityChangeCallback dummy function
 | 
			
		||||
func (i *DBIndexer) SetAvailabilityChangeCallback(callback func(bool)) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Ping checks if database is available
 | 
			
		||||
func (i *DBIndexer) Ping() bool {
 | 
			
		||||
	return db.GetEngine(db.DefaultContext).Ping() != nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Index dummy function
 | 
			
		||||
func (db *DBIndexer) Index(issue []*IndexerData) error {
 | 
			
		||||
func (i *DBIndexer) Index(issue []*IndexerData) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Delete dummy function
 | 
			
		||||
func (db *DBIndexer) Delete(ids ...int64) error {
 | 
			
		||||
func (i *DBIndexer) Delete(ids ...int64) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Close dummy function
 | 
			
		||||
func (db *DBIndexer) Close() {
 | 
			
		||||
func (i *DBIndexer) Close() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Search dummy function
 | 
			
		||||
func (db *DBIndexer) Search(kw string, repoIDs []int64, limit, start int) (*SearchResult, error) {
 | 
			
		||||
	total, ids, err := models.SearchIssueIDsByKeyword(kw, repoIDs, limit, start)
 | 
			
		||||
func (i *DBIndexer) Search(ctx context.Context, kw string, repoIDs []int64, limit, start int) (*SearchResult, error) {
 | 
			
		||||
	total, ids, err := models.SearchIssueIDsByKeyword(ctx, kw, repoIDs, limit, start)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user