Skip to content

Commit

Permalink
Merge pull request #6 from ComposableFi/rjonczy/fix-for-first-iteration
Browse files Browse the repository at this point in the history
do not post to slack when first iteration
  • Loading branch information
rjonczy authored Apr 30, 2024
2 parents 1eb3ec5 + 627f609 commit 84085ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func main() {
}

var lastProposalId string
firstIteration := true
for {
latestProposal, err := getLatestProposal(cosmosEndpoint)
if err != nil {
Expand All @@ -63,15 +64,17 @@ func main() {
}

// post to slack only if didn't posted before
if lastProposalId != latestProposal.ID {
if !firstIteration && lastProposalId != latestProposal.ID {
err = postToSlack(chainID, *latestProposal, slackWebhookURL)
if err != nil {
log.Errorf("Error posting to slack: %s\n", err)
continue
}
lastProposalId = latestProposal.ID
}

lastProposalId = latestProposal.ID
firstIteration = false

time.Sleep(interval)
}
}
4 changes: 4 additions & 0 deletions proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"fmt"
"io"
"net/http"
)
Expand Down Expand Up @@ -64,5 +65,8 @@ func getLatestProposal(cosmosEndpoint string) (*Proposal, error) {
if err != nil {
return nil, err
}
if len(proposalsData.Proposals) == 0 {
return nil, fmt.Errorf("no proposals found")
}
return &proposalsData.Proposals[0], nil
}

0 comments on commit 84085ce

Please sign in to comment.