mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 04:45:02 +02:00
feat: pick jobs of the runner only
This commit is contained in:
parent
ec673c0e79
commit
04634b9143
@ -179,17 +179,28 @@ func GetTaskByID(ctx context.Context, id int64) (*Task, error) {
|
||||
return &task, nil
|
||||
}
|
||||
|
||||
func CreateTaskForRunner(runner *Runner) (*Task, bool, error) {
|
||||
ctx, commiter, err := db.TxContext()
|
||||
func CreateTaskForRunner(ctx context.Context, runner *Runner) (*Task, bool, error) {
|
||||
dbCtx, commiter, err := db.TxContext()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
defer commiter.Close()
|
||||
ctx = dbCtx.WithContext(ctx)
|
||||
|
||||
e := db.GetEngine(ctx)
|
||||
|
||||
jobCond := builder.NewCond()
|
||||
if runner.RepoID != 0 {
|
||||
jobCond = builder.Eq{"repo_id": runner.RepoID}
|
||||
} else if runner.OwnerID != 0 {
|
||||
jobCond = builder.In("repo_id", builder.Select("id").From("repository").Where(builder.Eq{"owner_id": runner.OwnerID}))
|
||||
}
|
||||
if jobCond.IsValid() {
|
||||
jobCond = builder.In("run_id", builder.Select("id").From(Run{}.TableName()).Where(jobCond))
|
||||
}
|
||||
|
||||
var jobs []*RunJob
|
||||
if err := e.Where("task_id=? AND ready=?", 0, true).OrderBy("id").Find(&jobs); err != nil {
|
||||
if err := e.Where("task_id=? AND ready=?", 0, true).And(jobCond).OrderBy("id").Find(&jobs); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ func (s *Service) UpdateLog(
|
||||
}
|
||||
|
||||
func (s *Service) pickTask(ctx context.Context, runner *bots_model.Runner) (*runnerv1.Task, bool, error) {
|
||||
t, ok, err := bots_model.CreateTaskForRunner(runner)
|
||||
t, ok, err := bots_model.CreateTaskForRunner(ctx, runner)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("CreateTaskForRunner: %w", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user