From db3ade75e52c10e570f996baa0d1acaff7d5602b Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Thu, 30 May 2024 10:28:25 -0700 Subject: [PATCH] Fix TaskHandler.GetAttached(); and sorting in the task.Manager. Signed-off-by: Jeff Ortel --- api/task.go | 11 +++++++++-- task/manager.go | 14 ++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/api/task.go b/api/task.go index 15ccc9871..69b584e09 100644 --- a/api/task.go +++ b/api/task.go @@ -465,6 +465,7 @@ 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 @@ -472,12 +473,18 @@ func (h TaskHandler) GetAttached(ctx *gin.Context) { _ = 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)) } } diff --git a/task/manager.go b/task/manager.go index a8c0f8b9e..a42f73279 100644 --- a/task/manager.go +++ b/task/manager.go @@ -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{} @@ -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 } @@ -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) @@ -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) { @@ -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 { @@ -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 {