From 03bb60e036cc7784ad5df303598cfc0d45e2dc27 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Fri, 21 Jun 2024 15:59:41 -0700 Subject: [PATCH] Sort the ps output Provide consistent ordering for the ps command - longest duration listed first --- server/routes.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/routes.go b/server/routes.go index ff66663c0..76ead072f 100644 --- a/server/routes.go +++ b/server/routes.go @@ -1237,6 +1237,11 @@ func (s *Server) ProcessHandler(c *gin.Context) { models = append(models, mr) } + slices.SortStableFunc(models, func(i, j api.ProcessModelResponse) int { + // longest duration remaining listed first + return cmp.Compare(j.ExpiresAt.Unix(), i.ExpiresAt.Unix()) + }) + c.JSON(http.StatusOK, api.ProcessResponse{Models: models}) }