Skip to content

Commit

Permalink
ipfs: check that provider is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed May 5, 2024
1 parent 5e0d94a commit 6a29292
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ipfs/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type (
LastAnnouncement time.Time `json:"lastAnnouncement"`
}

Provider interface {

Check warning on line 21 in ipfs/provide.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21)

exported: exported type Provider should have comment or be unexported (revive)

Check warning on line 21 in ipfs/provide.go

View workflow job for this annotation

GitHub Actions / test

exported: exported type Provider should have comment or be unexported (revive)
Ready() bool
provider.ProvideMany
}

// A ReprovideStore stores CIDs that need to be periodically announced.
ReprovideStore interface {
ProvideCIDs(limit int) ([]PinnedCID, error)
Expand All @@ -27,7 +32,7 @@ type (

// A Reprovider periodically announces CIDs to the IPFS network.
type Reprovider struct {
provider provider.ProvideMany
provider Provider
store ReprovideStore
log *zap.Logger

Expand All @@ -53,7 +58,15 @@ func (r *Reprovider) Run(ctx context.Context, interval time.Duration) {
case <-ctx.Done():
return
case <-r.triggerProvide:
r.log.Debug("reprovide triggered")
case <-time.After(reprovideSleep):
r.log.Debug("reprovide sleep expired")
}

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

for {
Expand Down Expand Up @@ -106,7 +119,7 @@ func (r *Reprovider) Run(ctx context.Context, interval time.Duration) {
}

// NewReprovider creates a new reprovider.
func NewReprovider(provider provider.ProvideMany, store ReprovideStore, log *zap.Logger) *Reprovider {
func NewReprovider(provider Provider, store ReprovideStore, log *zap.Logger) *Reprovider {
return &Reprovider{
provider: provider,
store: store,
Expand Down

0 comments on commit 6a29292

Please sign in to comment.