Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: retry method added for vote failure case #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions voting-bot/client/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ func InitializeBotcommands(ctx types.Context) error {
result, err := voting.ExecVote(ctx, chainName, proposalID, granter.String(), voteOption, fromKey, metadata, memo, gasPrices, response)
if err != nil {
log.Printf("error on executing vote: %v", err)
response.ReportError(fmt.Errorf("error on executing vote: %v", err))
return
response.ReportError(fmt.Errorf("error on executing vote: %v, retrying...", err))
result, err = retryExecVote(ctx, chainName, proposalID, granter.String(), voteOption, fromKey, metadata, memo, gasPrices, response)
if err != nil {
log.Printf("Failed after retrying: %v", err)
return
}
}

response.Reply(result)
Expand Down Expand Up @@ -354,3 +358,23 @@ func formatTable(data [][]string) string {

return tableText
}

func retryExecVote(ctx types.Context, chainName string, proposalID string, granter string, voteOption string, fromKey string, metadata string, memo string, gasPrices string, response slacker.ResponseWriter) (result string, err error) {
for attempt := 1; attempt <= 5; attempt++ {
result, err = voting.ExecVote(ctx, chainName, proposalID, granter, voteOption, fromKey, metadata, memo, gasPrices, response)
if err == nil {
return result, nil
}
log.Printf("Error on attempt %d: %v", attempt, err)
// response.ReportError(fmt.Errorf("Error on attempt %d: %v", attempt, err))

if attempt == 5 {
return result, err
}

// retry in 5 seconds
time.Sleep(5 * time.Second)
}
response.ReportError(fmt.Errorf("Retry failed after 5 attempts"))
return result, fmt.Errorf("Retry failed after 5 attempts")
}