Skip to content

Commit

Permalink
Refactor monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Jul 13, 2022
1 parent 424ab96 commit f82472b
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions module/cmd/mhub2/cmd/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func AddMonitorCmd() *cobra.Command {
panic(err)
}

newText := func() string {
return fmt.Sprintf("Watching...\n%s", time.Now().Format(time.Stamp))
newText := func(t string) string {
return fmt.Sprintf("Watching...\n%s\n%s", time.Now().Format(time.Stamp), t)
}

startMsg, err := bot.Send(tgbotapi.NewMessage(int64(chatId), newText()))
startMsg, err := bot.Send(tgbotapi.NewMessage(int64(chatId), newText("")))
if err != nil {
panic(err)
}
Expand All @@ -61,21 +61,15 @@ func AddMonitorCmd() *cobra.Command {
println(err.Error())
}

startMsg, _ = bot.Send(tgbotapi.NewMessage(int64(chatId), newText()))
startMsg, _ = bot.Send(tgbotapi.NewMessage(int64(chatId), newText("")))
}

i := 0
for {
i++
if i%12 == 0 {
_, err := bot.Send(tgbotapi.NewEditMessageText(startMsg.Chat.ID, startMsg.MessageID, newText()))
if err != nil {
println(err.Error())
}
}

time.Sleep(time.Second * 5)

t := ""

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
handleErr(err)
Expand Down Expand Up @@ -105,7 +99,8 @@ func AddMonitorCmd() *cobra.Command {

chains := []types.ChainID{"ethereum", "minter", "bsc"}
for _, chain := range chains {
println(chain.String())
t = fmt.Sprintf("%s\n\n<b>%s</b>", t, chain.String())

delegatedKeys, err := queryClient.DelegateKeys(context.Background(), &types.DelegateKeysRequest{
ChainId: chain.String(),
})
Expand Down Expand Up @@ -140,7 +135,7 @@ func AddMonitorCmd() *cobra.Command {

for _, v := range vals.GetValidators() {
if v.OperatorAddress == k.ValidatorAddress {
println(v.GetMoniker(), response.GetEventNonce())
t = fmt.Sprintf("%s\n%s\t%d", t, v.GetMoniker(), response.GetEventNonce())
}
}

Expand All @@ -163,6 +158,16 @@ func AddMonitorCmd() *cobra.Command {
handleErr(errors.New("event nonce on some external network was not updated for too long. Check your orchestrators and minter-connector"))
continue
}

i++
if i%12 == 0 {
msg := tgbotapi.NewEditMessageText(startMsg.Chat.ID, startMsg.MessageID, newText(t))
msg.ParseMode = "html"
_, err := bot.Send(msg)
if err != nil {
println(err.Error())
}
}
}

return nil
Expand Down

0 comments on commit f82472b

Please sign in to comment.