Skip to content

Commit

Permalink
BEDS-306: monitoring: acquire current time with snowflake
Browse files Browse the repository at this point in the history
  • Loading branch information
invis-bitfly committed Sep 10, 2024
1 parent b7f67b6 commit 0f5097e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion backend/pkg/commons/utils/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/bwmarrin/snowflake"
"github.com/gobitfly/beaconchain/pkg/commons/log"
"github.com/google/uuid"
"golang.org/x/exp/rand"
)

// uuid that you can get - gets set to a random value on startup/first read
Expand All @@ -30,7 +31,8 @@ func GetSnowflake() int64 {
return v.(*snowflake.Node).Generate().Int64()
}

node, err := snowflake.NewNode(1)
nodeId := rand.Int63() & 0xFF
node, err := snowflake.NewNode(nodeId)
if err != nil {
log.Fatal(err, "snowflake generator failed to start", 0)
return 0
Expand Down
5 changes: 3 additions & 2 deletions backend/pkg/monitoring/services/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func NewStatusReport(id string, timeout time.Duration, check_interval time.Durat
return func(status constants.StatusType, metadata map[string]string) {
// acquire snowflake synchronously
flake := utils.GetSnowflake()
now := time.Now()
go func() {
if metadata == nil {
metadata = make(map[string]string)
Expand All @@ -60,9 +61,9 @@ func NewStatusReport(id string, timeout time.Duration, check_interval time.Durat
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

timeouts_at := time.Now().Add(1 * time.Minute)
timeouts_at := now.Add(1 * time.Minute)
if timeout != constants.Default {
timeouts_at = time.Now().Add(timeout)
timeouts_at = now.Add(timeout)
}
expires_at := timeouts_at.Add(5 * time.Minute)
if check_interval >= 5*time.Minute {
Expand Down

0 comments on commit 0f5097e

Please sign in to comment.