Skip to content

Commit

Permalink
Fix TaskHandler.GetAttached(); and sorting in the task.Manager.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed May 30, 2024
1 parent 3cf2a9a commit db3ade7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 9 additions & 2 deletions api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,19 +465,26 @@ func (h TaskHandler) GetAttached(ctx *gin.Context) {
}()
r := Task{}
r.With(m)
var files []*model.File
for _, ref := range r.Attached {
file := &model.File{}
err = h.DB(ctx).First(file, ref.ID).Error
if err != nil {
_ = ctx.Error(err)
return
}
dst := fmt.Sprintf("%.3d-%s", file.ID, file.Name)
err = tarWriter.AddFile(file.Path, dst)
err = tarWriter.AssertFile(file.Path)
if err != nil {
_ = ctx.Error(err)
return
}
files = append(files, file)
}
ctx.Status(http.StatusOK)
for _, file := range files {
_ = tarWriter.AddFile(
file.Path,
fmt.Sprintf("%.3d-%s", file.ID, file.Name))
}
}

Expand Down
14 changes: 8 additions & 6 deletions task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ func (m *Manager) postpone(list []*Task) (kept []*Task, err error) {
it := list[i]
jt := list[j]
return it.Priority < jt.Priority ||
it.ID > jt.ID
(it.Priority == jt.Priority &&
it.ID > jt.ID)
})
postponed := map[uint]any{}
released := map[uint]any{}
Expand Down Expand Up @@ -582,7 +583,6 @@ func (m *Manager) adjustPriority(list []*Task) (err error) {
pE := Priority{cluster: m.cluster}
escalated := pE.Escalate(list)
for _, task := range escalated {
Log.V(1).Info("Priority escalated.", "id", task.ID)
if task.State != Pending {
continue
}
Expand All @@ -592,7 +592,6 @@ func (m *Manager) adjustPriority(list []*Task) (err error) {
return
}
task.State = Ready
task.Event(Escalated)
err = m.DB.Save(task).Error
if err != nil {
err = liberr.Wrap(err)
Expand All @@ -610,7 +609,8 @@ func (m *Manager) createPod(list []*Task) (err error) {
it := list[i]
jt := list[j]
return it.Priority > jt.Priority ||
it.ID < jt.ID
(it.Priority == jt.Priority &&
it.ID < jt.ID)
})
for _, task := range list {
if !task.StateIn(Ready, QuotaBlocked) {
Expand Down Expand Up @@ -664,7 +664,8 @@ func (m *Manager) preempt(list []*Task) (err error) {
it := list[i]
jt := list[j]
return it.Priority > jt.Priority ||
it.ID < jt.ID
(it.Priority == jt.Priority &&
it.ID < jt.ID)
})
for _, task := range list {
switch task.State {
Expand Down Expand Up @@ -717,7 +718,8 @@ func (m *Manager) preempt(list []*Task) (err error) {
it := list[i]
jt := list[j]
return it.Priority < jt.Priority ||
it.ID > jt.ID
(it.Priority == jt.Priority &&
it.ID > jt.ID)
})
n := 0
for _, p := range preempt {
Expand Down

0 comments on commit db3ade7

Please sign in to comment.