File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -101,12 +101,17 @@ func StartPullRequestCheckDelayable(ctx context.Context, pr *issues_model.PullRe
101101 AddPullRequestToCheckQueue (pr .ID )
102102}
103103
104- func StartPullRequestCheckOnView (_ context.Context , pr * issues_model.PullRequest ) {
105- // TODO: its correctness totally depends on the "unique queue" feature.
106- // So duplicate "start" requests will be ignored if there is already a task in the queue
107- // Ideally in the future we should decouple the "unique queue" feature from the "start" request
104+ func StartPullRequestCheckOnView (ctx context.Context , pr * issues_model.PullRequest ) {
105+ // TODO: its correctness totally depends on the "unique queue" feature and the global lock .
106+ // So duplicate "start" requests will be ignored if there is already a task in the queue or one is running.
107+ // Ideally in the future we should decouple the "unique queue" feature from the "start" request.
108108 if pr .Status == issues_model .PullRequestStatusChecking {
109- AddPullRequestToCheckQueue (pr .ID )
109+ // When a PR check starts, the task is popped from the queue and the task handler acquires the global lock
110+ // So we need to acquire the global lock here to prevent from duplicate tasks
111+ _ , _ = globallock .TryLockAndDo (ctx , getPullWorkingLockKey (pr .ID ), func (ctx context.Context ) error {
112+ AddPullRequestToCheckQueue (pr .ID ) // the queue is a unique queue and won't add the same task again
113+ return nil
114+ })
110115 }
111116}
112117
You can’t perform that action at this time.
0 commit comments