Skip to content

Commit

Permalink
Merge pull request #4 from tczekajlo/timeout
Browse files Browse the repository at this point in the history
feat: [client] Print how much time left if a server limits session time
  • Loading branch information
tczekajlo authored Jan 11, 2021
2 parents 781981e + a69c091 commit d39dcab
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Copyright © 2020 tczekajlo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (c *Client) IsReady(data *pb.BackendData, opts ...interface{}) (bool, error
case <-timeout:
metrics.BackendReadyTimeoutTotal.Inc()
return false, errors.New("timed out")
// Got a tick, we should check on checkSomething()
// Got a tick
case <-ticker:
deploymentIsReady := false
serviceIsReady := false
Expand Down
39 changes: 35 additions & 4 deletions pkg/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,40 @@ func (s *SshareClient) runReceiver() {

func (s *SshareClient) sessionTimeoutClose(sigs chan os.Signal) {
if s.sessionTimeout != 0 {
timeout := time.After(time.Duration(s.sessionTimeout) * time.Second)
ticker := time.Tick(5 * time.Second)
now := time.Now()
end := now.Add(time.Duration(s.sessionTimeout) * time.Second)

s.log.Debugw("Session timeout is set", "timeout", s.sessionTimeout)
time.Sleep(time.Duration(s.sessionTimeout) * time.Second)
fmt.Println(color.YellowString(emoji.Sprintf("Session timed out :clock: The server that you're connected to allows for a session no longer than %v",
time.Duration(s.sessionTimeout)*time.Second)))
sigs <- syscall.SIGTERM

s.waitSpinner.UpdateCharSet(spinner.CharSets[21])
s.waitSpinner.Start()

for {
select {
// Got a timeout!
case <-timeout:
s.waitSpinner.Stop()

fmt.Println(color.YellowString(emoji.Sprintf("Session timed out :clock: The server that you're connected to allows for a session no longer than %v",
time.Duration(s.sessionTimeout)*time.Second)))

sigs <- syscall.SIGTERM
return
// Got a tick
case <-ticker:
diff := end.Sub(time.Now())
timeLeft := time.Time{}.Add(diff).Format("15:04:05")
s.spinnerNewMsg(
color.YellowString(
emoji.Sprintf(" Your session is time-limited by the server that you're connected to: %v left",
timeLeft),
),
)
}
}

}
}

Expand All @@ -220,6 +249,7 @@ func clean(sshareClient *SshareClient) {
cleanSend(client, sshareClient)

fmt.Println()
sshareClient.waitSpinner.Stop()
emoji.Println("Bye :wave:")
conn.Close()
os.Exit(0)
Expand Down Expand Up @@ -331,6 +361,7 @@ func (s *SshareClient) printAccessData() {
)
}
}
fmt.Println()
}

// RunClient runs gRPC client and establishes SSH tunnel
Expand Down

0 comments on commit d39dcab

Please sign in to comment.