Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rugwirobaker committed Oct 7, 2021
1 parent c0812bf commit 427dc6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
46 changes: 36 additions & 10 deletions cmd/logs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"time"

"github.com/superfly/flyctl/cmd/presenters"
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/internal/client"
Expand Down Expand Up @@ -45,26 +47,50 @@ func runLogs(cc *cmdctx.CmdContext) error {
VMID: cc.Config.GetString("instance"),
}

stream, err := logs.NewNatsStream(client, opts)
entries := make(chan logs.LogEntry, 2)

if err != nil {
terminal.Debugf("could not connect to wireguard tunnel, err: %v\n", err)
terminal.Debug("Falling back to log polling...")
stop := make(chan struct{})

stream, err = logs.NewPollingStream(client, opts)
go func() {
stream, err := logs.NewNatsStream(client, opts)
if err != nil {
return err
terminal.Debugf("could not connect to wireguard tunnel, err: %v\n", err)
terminal.Debug("Falling back to log polling...")
return
}
}

presenter := presenters.LogPresenter{}
time.Sleep(5 * time.Second)

stop <- struct{}{}

for entry := range stream.Stream(ctx, opts) {
entries <- entry
}
}()

entries := stream.Stream(ctx, opts)
go func() {
stream, err := logs.NewPollingStream(client, opts)
if err != nil {
return
}
for {
select {
case entry := <-stream.Stream(ctx, opts):
entries <- entry
case <-stop:
return
}
}

}()

presenter := presenters.LogPresenter{}

for {
select {
case <-ctx.Done():
return stream.Err()
close(entries)
return nil
case entry := <-entries:
presenter.FPrint(cc.Out, cc.OutputJSON(), entry)
}
Expand Down
2 changes: 1 addition & 1 deletion docstrings/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ browser to view the content.`,
return KeyStrings{"flyctl", "The Fly CLI",
`flyctl is a command line interface to the Fly.io platform.
It allows users to manage authentication, application launch,
It allows users to manage authentication, application launch,
deployment, network configuration, logging and more with just the
one command.
Expand Down

0 comments on commit 427dc6c

Please sign in to comment.