diff options
author | Lauris BH <lauris@nix.lv> | 2022-01-27 10:30:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 10:30:51 +0200 |
commit | 8038610a4279862a87e630e4f1d1077c510f9d15 (patch) | |
tree | 802489f8ddde899e76643ea157f9020f12ca1490 /modules/indexer/issues/db.go | |
parent | 2649eddcf0bb1190abab49c9d79ce19bfcf19e87 (diff) | |
download | gitea-8038610a4279862a87e630e4f1d1077c510f9d15.tar.gz gitea-8038610a4279862a87e630e4f1d1077c510f9d15.zip |
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
Diffstat (limited to 'modules/indexer/issues/db.go')
-rw-r--r-- | modules/indexer/issues/db.go | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/modules/indexer/issues/db.go b/modules/indexer/issues/db.go index f02cbddce8..e2badf64f2 100644 --- a/modules/indexer/issues/db.go +++ b/modules/indexer/issues/db.go @@ -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 } |