-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add stats server * App go version * Fix tests
- Loading branch information
1 parent
91fd030
commit a4e257f
Showing
29 changed files
with
815 additions
and
47 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
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
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
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
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
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,36 @@ | ||
package stats | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
const ( | ||
calcCheckDelay = time.Minute * 10 | ||
) | ||
|
||
type CalcTotalsWorker struct { | ||
service *Service | ||
} | ||
|
||
func NewCalcTotalsWorker(s *Service) *CalcTotalsWorker { | ||
return &CalcTotalsWorker{ | ||
service: s, | ||
} | ||
} | ||
|
||
func (w *CalcTotalsWorker) Start(ctx context.Context) error { | ||
for { | ||
if err := w.service.refreshTotals(); err != nil { | ||
log.Error().Err(err).Msg("calc totals worker") | ||
} | ||
|
||
select { | ||
case <-ctx.Done(): | ||
return nil | ||
case <-time.After(calcCheckDelay): | ||
} | ||
} | ||
} |
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,15 @@ | ||
package stats | ||
|
||
type Dao struct { | ||
Total int64 | ||
TotalVerified int64 | ||
} | ||
|
||
type Proposals struct { | ||
Total int64 | ||
} | ||
|
||
type Totals struct { | ||
Dao Dao | ||
Proposals Proposals | ||
} |
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,33 @@ | ||
package stats | ||
|
||
import ( | ||
"context" | ||
|
||
pb "github.com/goverland-labs/goverland-core-storage/protocol/storagepb" | ||
) | ||
|
||
type Server struct { | ||
pb.UnimplementedStatsServer | ||
|
||
service *Service | ||
} | ||
|
||
func NewServer(s *Service) *Server { | ||
return &Server{ | ||
service: s, | ||
} | ||
} | ||
|
||
func (s *Server) GetTotals(_ context.Context, _ *pb.GetTotalsRequest) (*pb.GetTotalsResponse, error) { | ||
totals := s.service.GetTotals() | ||
|
||
return &pb.GetTotalsResponse{ | ||
Dao: &pb.DaoStats{ | ||
Total: totals.Dao.Total, | ||
TotalVerified: totals.Dao.TotalVerified, | ||
}, | ||
Proposals: &pb.ProposalsStats{ | ||
Total: totals.Proposals.Total, | ||
}, | ||
}, nil | ||
} |
Oops, something went wrong.