Skip to content

Commit 81bbff4

Browse files
Eslam-Nawaraashraffouda
authored andcommitted
monitor changes in substrate url and update sub event listener accordingly
1 parent 0a0c7a9 commit 81bbff4

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

cmds/modules/noded/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/ed25519"
66
"fmt"
7+
"slices"
78
"time"
89

910
"github.com/cenkalti/backoff"
@@ -245,6 +246,29 @@ func action(cli *cli.Context) error {
245246
}
246247
}()
247248

249+
// monitor node env updates in substrate url
250+
go func() {
251+
for {
252+
<-time.After(10 * time.Minute)
253+
newEnv, err := environment.Get()
254+
if err != nil {
255+
log.Error().Err(err).Msg("failed to get updated config")
256+
continue
257+
}
258+
if !slices.Equal(env.SubstrateURL, newEnv.SubstrateURL) {
259+
sub, err = environment.GetSubstrate()
260+
if err != nil {
261+
log.Error().Err(err).Msg("failed to get updated substrate manager")
262+
}
263+
264+
env = newEnv
265+
events.UpdateSubstrateManager(sub)
266+
log.Debug().Strs("substrate_urls", newEnv.SubstrateURL).Msg("updated substrate events handler to use new substrate urls")
267+
268+
}
269+
}
270+
}()
271+
248272
log.Info().Uint32("twin", twin).Msg("node has been registered")
249273
idStub := stubs.NewIdentityManagerStub(redis)
250274
fetchCtx, cancel := context.WithTimeout(ctx, 30*time.Second)

0 commit comments

Comments
 (0)