Skip to content

Commit 056f9b8

Browse files
committed
update registrar to load env every time it trys to register
1 parent 88c17d2 commit 056f9b8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pkg/registrar/registrar.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Registrar struct {
7171
mutex sync.RWMutex
7272
}
7373

74-
func NewRegistrar(ctx context.Context, cl zbus.Client, env environment.Environment, info RegistrationInfo) *Registrar {
74+
func NewRegistrar(ctx context.Context, cl zbus.Client, info RegistrationInfo) *Registrar {
7575
r := Registrar{
7676
State{
7777
0,
@@ -82,7 +82,7 @@ func NewRegistrar(ctx context.Context, cl zbus.Client, env environment.Environme
8282
sync.RWMutex{},
8383
}
8484

85-
go r.register(ctx, cl, env, info)
85+
go r.register(ctx, cl, info)
8686
return &r
8787
}
8888

@@ -100,7 +100,7 @@ func (r *Registrar) getState() State {
100100

101101
// register a node and then blocks forever watching the node account. It tries to re-activate the
102102
// account if needed
103-
func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environment.Environment, info RegistrationInfo) {
103+
func (r *Registrar) register(ctx context.Context, cl zbus.Client, info RegistrationInfo) {
104104
if app.CheckFlag(app.LimitedCache) {
105105
r.setState(FailedState(errors.New("no disks")))
106106
return
@@ -116,6 +116,7 @@ func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environmen
116116
bo := backoff.WithContext(exp, ctx)
117117
register := func() {
118118
err := backoff.RetryNotify(func() error {
119+
env := environment.MustGet()
119120
nodeID, twinID, err := r.registration(ctx, cl, env, info)
120121
if err != nil {
121122
r.setState(FailedState(err))
@@ -145,6 +146,7 @@ func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environmen
145146
select {
146147
case <-ctx.Done():
147148
case <-time.After(monitorAccountEvery):
149+
env := environment.MustGet()
148150
if err := r.reActivate(ctx, cl, env); err != nil {
149151
log.Error().Err(err).Msg("failed to reactivate account")
150152
}

pkg/registrar_light/registrar.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Registrar struct {
7171
mutex sync.RWMutex
7272
}
7373

74-
func NewRegistrar(ctx context.Context, cl zbus.Client, env environment.Environment, info RegistrationInfo) *Registrar {
74+
func NewRegistrar(ctx context.Context, cl zbus.Client, info RegistrationInfo) *Registrar {
7575
r := Registrar{
7676
State{
7777
0,
@@ -81,7 +81,7 @@ func NewRegistrar(ctx context.Context, cl zbus.Client, env environment.Environme
8181
},
8282
sync.RWMutex{},
8383
}
84-
go r.register(ctx, cl, env, info)
84+
go r.register(ctx, cl, info)
8585
return &r
8686
}
8787

@@ -99,7 +99,7 @@ func (r *Registrar) getState() State {
9999

100100
// register a node and then blocks forever watching the node account. It tries to re-activate the
101101
// account if needed
102-
func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environment.Environment, info RegistrationInfo) {
102+
func (r *Registrar) register(ctx context.Context, cl zbus.Client, info RegistrationInfo) {
103103
if app.CheckFlag(app.LimitedCache) {
104104
r.setState(FailedState(errors.New("no disks")))
105105
return
@@ -115,6 +115,7 @@ func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environmen
115115
bo := backoff.WithContext(exp, ctx)
116116
register := func() {
117117
err := backoff.RetryNotify(func() error {
118+
env := environment.MustGet()
118119
nodeID, twinID, err := r.registration(ctx, cl, env, info)
119120
if err != nil {
120121
r.setState(FailedState(err))
@@ -144,6 +145,7 @@ func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environmen
144145
select {
145146
case <-ctx.Done():
146147
case <-time.After(monitorAccountEvery):
148+
env := environment.MustGet()
147149
if err := r.reActivate(ctx, cl, env); err != nil {
148150
log.Error().Err(err).Msg("failed to reactivate account")
149151
}

0 commit comments

Comments
 (0)