Skip to content

Commit

Permalink
[feat] Add nomad system garbage collection
Browse files Browse the repository at this point in the history
  • Loading branch information
cshintov committed Feb 29, 2024
1 parent d935e85 commit f5b0ae2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
19 changes: 18 additions & 1 deletion internal/tui/components/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"fmt"
"github.com/robinovitch61/wander/internal/fileio"
"os"
"os/exec"
"path"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/hashicorp/nomad/api"
"github.com/itchyny/gojq"
"github.com/robinovitch61/wander/internal/dev"
"github.com/robinovitch61/wander/internal/fileio"
"github.com/robinovitch61/wander/internal/tui/components/header"
"github.com/robinovitch61/wander/internal/tui/components/page"
"github.com/robinovitch61/wander/internal/tui/components/toast"
Expand Down Expand Up @@ -510,6 +510,23 @@ func (m *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
}
}

case key.Matches(msg, keymap.KeyMap.GarbageCollect):
err := m.client.System().GarbageCollect()
if err != nil {
// Create an error toast
toastMsg := fmt.Sprintf("Error performing system GC: %s", err)
toastStyle := style.ErrorToast
newToast := toast.New(toastMsg)
m.getCurrentPageModel().SetToast(newToast, toastStyle)
} else {
// Create a success toast
toastMsg := "System garbage collection completed successfully."
toastStyle := style.SuccessToast
newToast := toast.New(toastMsg)
m.getCurrentPageModel().SetToast(newToast, toastStyle)
}
return nil

case key.Matches(msg, keymap.KeyMap.Reload):
if m.currentPage.DoesReload() {
m.getCurrentPageModel().SetLoading(true)
Expand Down
5 changes: 5 additions & 0 deletions internal/tui/keymap/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type keyMap struct {
Spec key.Binding
Wrap key.Binding
AdminMenu key.Binding
GarbageCollect key.Binding
}

var KeyMap = keyMap{
Expand Down Expand Up @@ -113,4 +114,8 @@ var KeyMap = keyMap{
key.WithKeys("X"),
key.WithHelp("X", "admin"),
),
GarbageCollect: key.NewBinding(
key.WithKeys("c"),
key.WithHelp("c", "system gc"),
),
}
6 changes: 4 additions & 2 deletions internal/tui/nomad/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package nomad

import (
"fmt"
"strings"
"time"

"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/hashicorp/nomad/api"
Expand All @@ -11,8 +14,6 @@ import (
"github.com/robinovitch61/wander/internal/tui/formatter"
"github.com/robinovitch61/wander/internal/tui/keymap"
"github.com/robinovitch61/wander/internal/tui/style"
"strings"
"time"
)

type Page int8
Expand Down Expand Up @@ -507,6 +508,7 @@ func GetPageKeyHelp(
firstRow = append(firstRow, keymap.KeyMap.Reload)
}
}
firstRow = append(firstRow, keymap.KeyMap.GarbageCollect)

viewportKeyMap := viewport.GetKeyMap()
secondRow := []key.Binding{viewportKeyMap.Save, keymap.KeyMap.Wrap}
Expand Down

0 comments on commit f5b0ae2

Please sign in to comment.