Skip to content

Commit

Permalink
chore: add in suspend stop auto refresh condition (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
keidarcy authored Apr 22, 2024
1 parent 4cf7d4f commit 35980f3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion internal/view/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type App struct {
sessions []*PortForwardingSession
// Current primary kind table row index for auto refresh to keep row selected
rowIndex int
// Specify in tview app suspend or not
isSuspended bool
}

func newApp(option Option) (*App, error) {
Expand Down Expand Up @@ -218,7 +220,7 @@ func (app *App) start() error {
go func() {
for {
<-ticker.C
if app.secondaryKind == EmptyKind {
if app.secondaryKind == EmptyKind && !app.isSuspended {
app.showPrimaryKindPage(app.kind, true)
logger.Debug("Auto refresh")
app.Application.Draw()
Expand Down
2 changes: 2 additions & 0 deletions internal/view/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (v *view) cpForm() (*tview.Form, *string) {
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)

v.app.Suspend(func() {
v.app.isSuspended = true
logger.Infof("Exec: `%s %s`", awsCli, strings.Join(uploadArgs, " "))
uploadCmd := exec.Command(bin, uploadArgs...)
uploadCmd.Stdin, uploadCmd.Stdout = os.Stdin, os.Stdout
Expand Down Expand Up @@ -222,6 +223,7 @@ func (v *view) cpForm() (*tview.Form, *string) {

signal.Stop(interrupt)
close(interrupt)
v.app.isSuspended = false
})

if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion internal/view/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (v *view) execShell() {
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)

v.app.Suspend(func() {
v.app.isSuspended = true
bin, _ := exec.LookPath(awsCli)
cmdArgs := append(*args, v.app.Option.Shell)
logger.Infof("Exec: `%s %s`", bin, strings.Join(cmdArgs, " "))
Expand All @@ -42,6 +43,7 @@ func (v *view) execShell() {
// return signal
signal.Stop(interrupt)
close(interrupt)
v.app.isSuspended = false
})
}

Expand Down Expand Up @@ -76,23 +78,28 @@ func (v *view) execCommandForm() (*tview.Form, *string) {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
v.app.Suspend(func() {
v.app.isSuspended = true
bin, _ := exec.LookPath(awsCli)
cmdArgs := append(*args, execCmd)
logger.Infof("Exec: `%s %s`", bin, strings.Join(cmdArgs, " "))

cmd := exec.Command(bin, cmdArgs...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
_, err = cmd.Stdout.Write([]byte(fmt.Sprintf(execBannerFmt, *v.app.cluster.ClusterName, *v.app.service.ServiceName, utils.ArnToName(v.app.task.TaskArn), containerName)))
time.Sleep(1 * time.Second)

cmd.Stdout.Write([]byte(fmt.Sprintf("\nExecute: \"%s\"\n", execCmd)))
err = cmd.Run()

cmd.Stdout.Write([]byte("\nDone...\n"))
time.Sleep(2 * time.Second)
time.Sleep(3 * time.Second)

signal.Stop(interrupt)
close(interrupt)

v.closeModal()
v.reloadResource(false)
v.app.isSuspended = false
})
})
return f, &title
Expand Down
2 changes: 2 additions & 0 deletions internal/view/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (v *view) openInEditor(beforeJson []byte) {

logger.Infof("%s open %s", bin, tmpfile.Name())
v.app.Suspend(func() {
v.app.isSuspended = true
cmd := exec.Command(bin, tmpfile.Name())
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr

Expand Down Expand Up @@ -223,6 +224,7 @@ func (v *view) openInEditor(beforeJson []byte) {
}

v.showTaskDefinitionConfirm(register)
v.app.isSuspended = false
})
}

Expand Down
2 changes: 2 additions & 0 deletions internal/view/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (v *view) realtimeAwsLog(entity Entity) {
logger.Infof("Exec: `%s %s`", awsCli, strings.Join(args, " "))

v.app.Suspend(func() {
v.app.isSuspended = true
cmd := exec.Command(bin, args...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr

Expand All @@ -169,6 +170,7 @@ func (v *view) realtimeAwsLog(entity Entity) {
// return signal
signal.Stop(interrupt)
close(interrupt)
v.app.isSuspended = false
})
}
}
4 changes: 2 additions & 2 deletions internal/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const (

awsCli = "aws"
smpCi = "session-manager-plugin"
execBannerFmt = "\033[1;31m<<E1S-ECS-EXEC>>\033[0m: \n#######################################\n\033[1;32mCluster\033[0m: \"%s\" \n\033[1;32mService\033[0m: \"%s\" \n\033[1;32mTask\033[0m: \"%s\" \n\033[1;32mContainer\033[0m: \"%s\"\n#######################################\n"
realtimeLogFmt = "\033[1;31m<<E1S-LOGS-TAIL>>\033[0m: \n#######################################\n\033[1;32mCluster\033[0m: \"%s\" \n\033[1;32mService\033[0m: \"%s\" \n\033[1;32mLogGroup\033[0m: \"%s\"\n#######################################\n"
execBannerFmt = "\n\033[1;31m<<E1S-ECS-EXEC>>\033[0m: \n#######################################\n\033[1;32mCluster\033[0m: \"%s\" \n\033[1;32mService\033[0m: \"%s\" \n\033[1;32mTask\033[0m: \"%s\" \n\033[1;32mContainer\033[0m: \"%s\"\n#######################################\n"
realtimeLogFmt = "\n\033[1;31m<<E1S-LOGS-TAIL>>\033[0m: \n#######################################\n\033[1;32mCluster\033[0m: \"%s\" \n\033[1;32mService\033[0m: \"%s\" \n\033[1;32mLogGroup\033[0m: \"%s\"\n#######################################\n"
)

// Base struct of different views
Expand Down

0 comments on commit 35980f3

Please sign in to comment.