Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add nomad system garbage collection #135

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Owner

@robinovitch61 robinovitch61 Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this action hangs for one reason or another, it will hang the whole wander app (unable to navigate, quit, etc). This is why wander runs async actions in Cmds, which run in bubbletea in non-deterministic order in goroutines outside the main application event loop. See https://github.com/charmbracelet/bubbletea/tree/master/tutorials/commands/ for details :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Will keep that in mind.

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
Loading