Skip to content

Commit fd08159

Browse files
committed
fix more problems
1 parent 03a2c06 commit fd08159

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

models/actions/task.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,16 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
257257
// e.g. we would start again from zero if no job matches our known labels
258258
// For stable paging
259259
var lastUpdated timeutil.TimeStamp
260+
// TODO: a more efficient way to filter labels
261+
log.Trace("runner labels: %v", runner.AgentLabels)
262+
backoffGen := rand.New(rand.NewSource(time.Now().UnixNano() ^ runner.ID))
260263
for page := 0; job == nil; page++ {
261264
var jobs []*ActionRunJob
262265
// Load only 10 job in a batch without all fields for memory / db load reduction
263266
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 {
264267
return nil, false, err
265268
}
266-
if len(jobs) == 0 {
267-
break
268-
}
269269

270-
// TODO: a more efficient way to filter labels
271-
log.Trace("runner labels: %v", runner.AgentLabels)
272-
backoffGen := rand.New(rand.NewSource(time.Now().UnixNano() ^ runner.ID))
273270
for _, v := range jobs {
274271
if runner.CanMatchLabels(v.RunsOn) {
275272
// Reserve our job before preparing task, otherwise continue searching
@@ -287,6 +284,9 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
287284
}
288285
lastUpdated = v.Updated
289286
}
287+
if len(jobs) < limit {
288+
break
289+
}
290290
// Randomly distribute retries over time to reduce contention
291291
jitter := time.Duration(backoffGen.Int63n(int64(util.Iif(page < 4, page+1, 5))*20)) * time.Millisecond // random jitter
292292
select {

0 commit comments

Comments
 (0)