Skip to content

Commit 2ddd476

Browse files
committed
docker ps sometimes lists years ago
This should be more accurate Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent 5b56415 commit 2ddd476

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

cmd/cli/commands/ps.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,18 @@ func psTable(ps []desktop.BackendStatus) string {
5959
modelName = stripDefaultsFromModelName(modelName)
6060
}
6161

62-
lastUsed := "in use"
63-
if !status.LastUsed.IsZero() {
62+
var lastUsed string
63+
if status.InUse {
64+
lastUsed = "in use"
65+
} else if !status.LastUsed.IsZero() {
6466
duration := time.Since(status.LastUsed)
6567
if duration < 0 {
6668
duration = 0
6769
}
6870
lastUsed = units.HumanDuration(duration) + " ago"
71+
} else {
72+
// This case should not happen if InUse is properly set, but fallback to "in use" for zero time
73+
lastUsed = "in use"
6974
}
7075

7176
table.Append([]string{

cmd/cli/desktop/desktop.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ type BackendStatus struct {
586586
Mode string `json:"mode"`
587587
// LastUsed represents when this backend was last used (if it's idle)
588588
LastUsed time.Time `json:"last_used,omitempty"`
589+
// InUse indicates whether this backend is currently handling a request
590+
InUse bool `json:"in_use,omitempty"`
589591
}
590592

591593
func (c *Client) PS() ([]BackendStatus, error) {

pkg/inference/scheduling/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ type BackendStatus struct {
6464
Mode string `json:"mode"`
6565
// LastUsed represents when this (backend, model, mode) tuple was last used
6666
LastUsed time.Time `json:"last_used,omitempty"`
67+
// InUse indicates whether this backend is currently handling a request
68+
InUse bool `json:"in_use,omitempty"`
6769
}
6870

6971
// DiskUsage represents the disk usage of the models and default backend.

pkg/inference/scheduling/scheduler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func (s *Scheduler) getLoaderStatus(ctx context.Context) []BackendStatus {
319319
ModelName: runnerInfo.modelRef,
320320
Mode: key.mode.String(),
321321
LastUsed: time.Time{},
322+
InUse: s.loader.references[runnerInfo.slot] > 0,
322323
}
323324

324325
if s.loader.references[runnerInfo.slot] == 0 {

0 commit comments

Comments
 (0)