Skip to content

Commit 91617c3

Browse files
author
Earl Warren
committed
Merge pull request '[TEST] make the indexer and pull tasks cancellable (without shutdown)' (#3141) from oliverpool/forgejo:cancellable_queues into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3141 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
2 parents 0905961 + d79690c commit 91617c3

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

modules/indexer/code/indexer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@ func Init() {
120120
case "bleve", "elasticsearch":
121121
handler := func(items ...*internal.IndexerData) (unhandled []*internal.IndexerData) {
122122
indexer := *globalIndexer.Load()
123+
// make it a process to allow for cancellation (especially during integration tests where no global shutdown happens)
124+
batchCtx, _, finished := process.GetManager().AddContext(ctx, "CodeIndexer batch")
125+
defer finished()
123126
for _, indexerData := range items {
124127
log.Trace("IndexerData Process Repo: %d", indexerData.RepoID)
125-
if err := index(ctx, indexer, indexerData.RepoID); err != nil {
128+
if err := index(batchCtx, indexer, indexerData.RepoID); err != nil {
126129
unhandled = append(unhandled, indexerData)
127130
if !setting.IsInTesting {
128131
log.Error("Codes indexer handler: index error for repo %v: %v", indexerData.RepoID, err)

services/pull/pull.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"code.gitea.io/gitea/modules/graceful"
2727
"code.gitea.io/gitea/modules/json"
2828
"code.gitea.io/gitea/modules/log"
29+
"code.gitea.io/gitea/modules/process"
2930
repo_module "code.gitea.io/gitea/modules/repository"
3031
"code.gitea.io/gitea/modules/setting"
3132
"code.gitea.io/gitea/modules/sync"
@@ -296,8 +297,12 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
296297
// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
297298
// and generate new patch for testing as needed.
298299
func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, isSync bool, oldCommitID, newCommitID string) {
299-
log.Trace("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch)
300-
graceful.GetManager().RunWithShutdownContext(func(ctx context.Context) {
300+
description := fmt.Sprintf("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch)
301+
log.Trace(description)
302+
graceful.GetManager().RunWithShutdownContext(func(shutdownCtx context.Context) {
303+
// make it a process to allow for cancellation (especially during integration tests where no global shutdown happens)
304+
ctx, _, finished := process.GetManager().AddContext(shutdownCtx, description)
305+
defer finished()
301306
// There is no sensible way to shut this down ":-("
302307
// If you don't let it run all the way then you will lose data
303308
// TODO: graceful: AddTestPullRequestTask needs to become a queue!

0 commit comments

Comments
 (0)