|
5 | 5 | package pull
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "context" |
8 | 9 | "fmt"
|
9 | 10 |
|
10 | 11 | "code.gitea.io/gitea/models"
|
11 | 12 | "code.gitea.io/gitea/modules/git"
|
| 13 | + "code.gitea.io/gitea/modules/graceful" |
12 | 14 | "code.gitea.io/gitea/modules/log"
|
13 | 15 | "code.gitea.io/gitea/modules/notification"
|
14 | 16 | issue_service "code.gitea.io/gitea/services/issue"
|
@@ -44,6 +46,7 @@ func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *m
|
44 | 46 | return fmt.Errorf("git.OpenRepository: %v", err)
|
45 | 47 | }
|
46 | 48 | go func() {
|
| 49 | + // FIXME: graceful: We need to tell the manager we're doing something... |
47 | 50 | err := requests.InvalidateCodeComments(doer, gitRepo, branch)
|
48 | 51 | if err != nil {
|
49 | 52 | log.Error("PullRequestList.InvalidateCodeComments: %v", err)
|
@@ -72,37 +75,43 @@ func addHeadRepoTasks(prs []*models.PullRequest) {
|
72 | 75 | // and generate new patch for testing as needed.
|
73 | 76 | func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSync bool) {
|
74 | 77 | log.Trace("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch)
|
75 |
| - prs, err := models.GetUnmergedPullRequestsByHeadInfo(repoID, branch) |
76 |
| - if err != nil { |
77 |
| - log.Error("Find pull requests [head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err) |
78 |
| - return |
79 |
| - } |
| 78 | + graceful.GetManager().RunWithShutdownContext(func(ctx context.Context) { |
| 79 | + // There is no sensible way to shut this down ":-(" |
| 80 | + // If you don't let it run all the way then you will lose data |
| 81 | + // FIXME: graceful: AddTestPullRequestTask needs to become a queue! |
80 | 82 |
|
81 |
| - if isSync { |
82 |
| - requests := models.PullRequestList(prs) |
83 |
| - if err = requests.LoadAttributes(); err != nil { |
84 |
| - log.Error("PullRequestList.LoadAttributes: %v", err) |
85 |
| - } |
86 |
| - if invalidationErr := checkForInvalidation(requests, repoID, doer, branch); invalidationErr != nil { |
87 |
| - log.Error("checkForInvalidation: %v", invalidationErr) |
| 83 | + prs, err := models.GetUnmergedPullRequestsByHeadInfo(repoID, branch) |
| 84 | + if err != nil { |
| 85 | + log.Error("Find pull requests [head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err) |
| 86 | + return |
88 | 87 | }
|
89 |
| - if err == nil { |
90 |
| - for _, pr := range prs { |
91 |
| - pr.Issue.PullRequest = pr |
92 |
| - notification.NotifyPullRequestSynchronized(doer, pr) |
| 88 | + |
| 89 | + if isSync { |
| 90 | + requests := models.PullRequestList(prs) |
| 91 | + if err = requests.LoadAttributes(); err != nil { |
| 92 | + log.Error("PullRequestList.LoadAttributes: %v", err) |
| 93 | + } |
| 94 | + if invalidationErr := checkForInvalidation(requests, repoID, doer, branch); invalidationErr != nil { |
| 95 | + log.Error("checkForInvalidation: %v", invalidationErr) |
| 96 | + } |
| 97 | + if err == nil { |
| 98 | + for _, pr := range prs { |
| 99 | + pr.Issue.PullRequest = pr |
| 100 | + notification.NotifyPullRequestSynchronized(doer, pr) |
| 101 | + } |
93 | 102 | }
|
94 | 103 | }
|
95 |
| - } |
96 | 104 |
|
97 |
| - addHeadRepoTasks(prs) |
| 105 | + addHeadRepoTasks(prs) |
98 | 106 |
|
99 |
| - log.Trace("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests", repoID, branch) |
100 |
| - prs, err = models.GetUnmergedPullRequestsByBaseInfo(repoID, branch) |
101 |
| - if err != nil { |
102 |
| - log.Error("Find pull requests [base_repo_id: %d, base_branch: %s]: %v", repoID, branch, err) |
103 |
| - return |
104 |
| - } |
105 |
| - for _, pr := range prs { |
106 |
| - AddToTaskQueue(pr) |
107 |
| - } |
| 107 | + log.Trace("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests", repoID, branch) |
| 108 | + prs, err = models.GetUnmergedPullRequestsByBaseInfo(repoID, branch) |
| 109 | + if err != nil { |
| 110 | + log.Error("Find pull requests [base_repo_id: %d, base_branch: %s]: %v", repoID, branch, err) |
| 111 | + return |
| 112 | + } |
| 113 | + for _, pr := range prs { |
| 114 | + AddToTaskQueue(pr) |
| 115 | + } |
| 116 | + }) |
108 | 117 | }
|
0 commit comments