Skip to content

Commit

Permalink
Merge pull request #2427 from threefoldtech/main_location_updater
Browse files Browse the repository at this point in the history
init node location updater
  • Loading branch information
Omarabdul3ziz authored Oct 9, 2024
2 parents 1fbeaa7 + 7e0ee7d commit c812462
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/geoip/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// Location holds the result of a geoip request
type Location struct {
Longitute float64 `json:"longitude"`
Longitude float64 `json:"longitude"`
Latitude float64 `json:"latitude"`
Continent string `json:"continent"`
Country string `json:"country_name"`
Expand Down Expand Up @@ -45,7 +45,7 @@ func Fetch() (Location, error) {

func getLocation(geoIPService string) (Location, error) {
l := Location{
Longitute: 0.0,
Longitude: 0.0,
Latitude: 0.0,
Continent: "Unknown",
Country: "Unknown",
Expand Down
2 changes: 1 addition & 1 deletion pkg/registrar/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func registerNode(
}

location := substrate.Location{
Longitude: fmt.Sprint(info.Location.Longitute),
Longitude: fmt.Sprint(info.Location.Longitude),
Latitude: fmt.Sprint(info.Location.Latitude),
Country: info.Location.Country,
City: info.Location.City,
Expand Down
7 changes: 6 additions & 1 deletion pkg/registrar/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (
InProgress RegistrationState = "InProgress"
Done RegistrationState = "Done"

monitorAccountEvery = 30 * time.Minute
monitorAccountEvery = 30 * time.Minute
updateNodeInfoInterval = 24 * time.Hour
)

var (
Expand Down Expand Up @@ -80,6 +81,7 @@ func NewRegistrar(ctx context.Context, cl zbus.Client, env environment.Environme
},
sync.RWMutex{},
}

go r.register(ctx, cl, env, info)
return &r
}
Expand Down Expand Up @@ -146,6 +148,9 @@ func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environmen
if err := r.reActivate(ctx, cl, env); err != nil {
log.Error().Err(err).Msg("failed to reactivate account")
}
case <-time.After(updateNodeInfoInterval):
log.Info().Msg("update interval passed, re-register")
register()
case <-addressesUpdate:
log.Info().Msg("zos address has changed, re-register")
register()
Expand Down

0 comments on commit c812462

Please sign in to comment.