Skip to content

Commit

Permalink
DEVPROD-7676 Filter set tasks scheduled time in memory (#8406)
Browse files Browse the repository at this point in the history
  • Loading branch information
bynn authored Oct 18, 2024
1 parent 3393452 commit 20c659a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
14 changes: 11 additions & 3 deletions model/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1385,18 +1385,26 @@ func (t *Task) SetGeneratedTasksToActivate(buildVariantName, taskName string) er
func SetTasksScheduledTime(tasks []Task, scheduledTime time.Time) error {
ids := []string{}
for i := range tasks {
tasks[i].ScheduledTime = scheduledTime
ids = append(ids, tasks[i].Id)
// Skip tasks with scheduled time to prevent large updates
if utility.IsZeroTime(tasks[i].ScheduledTime) {
tasks[i].ScheduledTime = scheduledTime
ids = append(ids, tasks[i].Id)
}

// Display tasks are considered scheduled when their first exec task is scheduled
if tasks[i].IsPartOfDisplay() {
ids = append(ids, utility.FromStringPtr(tasks[i].DisplayTaskId))
}
}
// Remove duplicates to prevent large updates
uniqueIDs := utility.UniqueStrings(ids)
if len(uniqueIDs) == 0 {
return nil
}
_, err := UpdateAll(
bson.M{
IdKey: bson.M{
"$in": ids,
"$in": uniqueIDs,
},
ScheduledTimeKey: bson.M{
"$lte": utility.ZeroTime,
Expand Down
21 changes: 21 additions & 0 deletions model/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,27 @@ func TestSetTasksScheduledTime(t *testing.T) {
})
})

Convey("if we update a third time", func() {
newTime := time.Unix(99999999, 0)
So(newTime, ShouldHappenAfter, testTime)
So(SetTasksScheduledTime(tasks, newTime), ShouldBeNil)

Convey("nothing should have updated", func() {
t0, err := FindOne(db.Query(ById("t0")))
So(err, ShouldBeNil)
So(t0.ScheduledTime.Round(oneMs), ShouldResemble, testTime)
t1, err := FindOne(db.Query(ById("t1")))
So(err, ShouldBeNil)
So(t1.ScheduledTime.Round(oneMs), ShouldResemble, newTime)
t2, err := FindOne(db.Query(ById("t2")))
So(err, ShouldBeNil)
So(t2.ScheduledTime.Round(oneMs), ShouldResemble, testTime)
t3, err := FindOne(db.Query(ById("t3")))
So(err, ShouldBeNil)
So(t3.ScheduledTime.Round(oneMs), ShouldResemble, testTime)
})
})

})

})
Expand Down

0 comments on commit 20c659a

Please sign in to comment.