Add a transaction to pickTask (#33543)

In the old `pickTask`, when getting secrets or variables failed, the
task could get stuck in the `running` status (task status is `running`
but the runner did not fetch the task). To fix this issue, these steps
should be in one transaction.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit 06f10656369c7e4274ae4e9f9edb21e1cac520d9)
This commit is contained in:
Zettat123 2025-02-12 00:09:43 +08:00 committed by Gusted
commit e932f89a13
No known key found for this signature in database
GPG key ID: FD821B732837125F
3 changed files with 108 additions and 96 deletions

View file

@ -158,7 +158,7 @@ func (s *Service) FetchTask(
// if the task version in request is not equal to the version in db,
// it means there may still be some tasks not be assigned.
// try to pick a task for the runner that send the request.
if t, ok, err := pickTask(ctx, runner); err != nil {
if t, ok, err := actions_service.PickTask(ctx, runner); err != nil {
log.Error("pick task failed: %v", err)
return nil, status.Errorf(codes.Internal, "pick task: %v", err)
} else if ok {