Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `akashctl events` command * Fix lint issues
- Loading branch information
1 parent
f1c6e67
commit 8140c66
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
ccontext "github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/ovrclk/akash/cmd/common" | ||
"github.com/ovrclk/akash/events" | ||
"github.com/ovrclk/akash/pubsub" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
// EventCmd prints out events in real time | ||
func EventCmd(cdc *codec.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "events", | ||
Short: "Prints out akash events in real time", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return common.RunForever(func(ctx context.Context) error { | ||
return getEvents(ctx, cdc, cmd, args) | ||
}) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func getEvents(ctx context.Context, cdc *codec.Codec, _ *cobra.Command, _ []string) error { | ||
cctx := ccontext.NewCLIContext().WithCodec(cdc) | ||
|
||
if err := cctx.Client.Start(); err != nil { | ||
return err | ||
} | ||
|
||
bus := pubsub.NewBus() | ||
defer bus.Close() | ||
|
||
group, ctx := errgroup.WithContext(ctx) | ||
|
||
subscriber, err := bus.Subscribe() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
group.Go(func() error { | ||
return events.Publish(ctx, cctx.Client, "akash-cli", bus) | ||
}) | ||
|
||
group.Go(func() error { | ||
for { | ||
select { | ||
case <-subscriber.Done(): | ||
return nil | ||
case ev := <-subscriber.Events(): | ||
cctx.PrintOutput(ev) | ||
} | ||
} | ||
}) | ||
|
||
return group.Wait() | ||
} |