mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-11 02:14:58 +01:00
fix more problems
This commit is contained in:
parent
03a2c06347
commit
fd08159c18
@ -257,19 +257,16 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
|
|||||||
// e.g. we would start again from zero if no job matches our known labels
|
// e.g. we would start again from zero if no job matches our known labels
|
||||||
// For stable paging
|
// For stable paging
|
||||||
var lastUpdated timeutil.TimeStamp
|
var lastUpdated timeutil.TimeStamp
|
||||||
|
// TODO: a more efficient way to filter labels
|
||||||
|
log.Trace("runner labels: %v", runner.AgentLabels)
|
||||||
|
backoffGen := rand.New(rand.NewSource(time.Now().UnixNano() ^ runner.ID))
|
||||||
for page := 0; job == nil; page++ {
|
for page := 0; job == nil; page++ {
|
||||||
var jobs []*ActionRunJob
|
var jobs []*ActionRunJob
|
||||||
// Load only 10 job in a batch without all fields for memory / db load reduction
|
// Load only 10 job in a batch without all fields for memory / db load reduction
|
||||||
if err := e.Where("task_id=? AND status=? AND updated>?", 0, StatusWaiting, lastUpdated).Cols("id", "runs_on").And(jobCond).Asc("updated", "id").Limit(limit).Find(&jobs); err != nil {
|
if err := e.Where("task_id=? AND status=? AND updated>?", 0, StatusWaiting, lastUpdated).Cols("id", "runs_on").And(jobCond).Asc("updated", "id").Limit(limit).Find(&jobs); err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if len(jobs) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: a more efficient way to filter labels
|
|
||||||
log.Trace("runner labels: %v", runner.AgentLabels)
|
|
||||||
backoffGen := rand.New(rand.NewSource(time.Now().UnixNano() ^ runner.ID))
|
|
||||||
for _, v := range jobs {
|
for _, v := range jobs {
|
||||||
if runner.CanMatchLabels(v.RunsOn) {
|
if runner.CanMatchLabels(v.RunsOn) {
|
||||||
// Reserve our job before preparing task, otherwise continue searching
|
// Reserve our job before preparing task, otherwise continue searching
|
||||||
@ -287,6 +284,9 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
|
|||||||
}
|
}
|
||||||
lastUpdated = v.Updated
|
lastUpdated = v.Updated
|
||||||
}
|
}
|
||||||
|
if len(jobs) < limit {
|
||||||
|
break
|
||||||
|
}
|
||||||
// Randomly distribute retries over time to reduce contention
|
// Randomly distribute retries over time to reduce contention
|
||||||
jitter := time.Duration(backoffGen.Int63n(int64(util.Iif(page < 4, page+1, 5))*20)) * time.Millisecond // random jitter
|
jitter := time.Duration(backoffGen.Int63n(int64(util.Iif(page < 4, page+1, 5))*20)) * time.Millisecond // random jitter
|
||||||
select {
|
select {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user