Skip to content

Commit

Permalink
ipfs: move ready check out of provide loop
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed May 13, 2024
1 parent e72989d commit e96ac5d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ipfs/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ func (r *Reprovider) Run(ctx context.Context, interval, timeout time.Duration, b
var once sync.Once
once.Do(func() {
var reprovideSleep time.Duration

for {
if r.provider.Ready() {
break
}
r.log.Debug("provider not ready")
time.Sleep(30 * time.Second)
}

for {
r.log.Debug("sleeping until next reprovide time", zap.Duration("duration", reprovideSleep))
select {
Expand All @@ -65,12 +74,6 @@ func (r *Reprovider) Run(ctx context.Context, interval, timeout time.Duration, b
r.log.Debug("reprovide sleep expired")
}

if !r.provider.Ready() {
r.log.Debug("provider not ready")
reprovideSleep = time.Minute
continue
}

doProvide := func(ctx context.Context, keys []multihash.Multihash) error {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
Expand Down

0 comments on commit e96ac5d

Please sign in to comment.