Skip to content

Commit

Permalink
[tgbot] retry loop on start
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Nov 8, 2023
1 parent 9e1cd63 commit 211c05e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions web/service/tgbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
}
}

bot, err = tgbotapi.NewBotAPI(tgBottoken)
if err != nil {
fmt.Println("Get tgbot's api error:", err)
return err
for {
bot, err = tgbotapi.NewBotAPI(tgBottoken)
if err != nil {
fmt.Println("Get tgbot's api error:", err)
fmt.Println("Retrying after 10 secound...")
time.Sleep(10 * time.Second)
} else {
fmt.Println("Tgbot connected!")
break
}
}
bot.Debug = false

Expand Down
2 changes: 1 addition & 1 deletion web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (s *Server) Start() (err error) {
isTgbotenabled, err := s.settingService.GetTgbotenabled()
if (err == nil) && (isTgbotenabled) {
tgBot := s.tgbotService.NewTgbot()
tgBot.Start(i18nFS)
go tgBot.Start(i18nFS)
}

return nil
Expand Down

0 comments on commit 211c05e

Please sign in to comment.