feat: add methods to list pending deals and force publish

This commit is contained in:
Dirk McCormick 2021-02-05 15:56:50 +01:00
parent dc6392db49
commit 4676fd6753

View File

@ -121,6 +121,44 @@ func newDealPublisher(
}
}
// PendingInfo has info about pending deals and when they are due to be
// published
type PendingInfo struct {
deals []*pendingDeal
publishPeriodStart time.Time
publishPeriod time.Duration
}
// PendingDeals returns the list of deals that are queued up to be published
func (p *DealPublisher) PendingDeals() *PendingInfo {
p.lk.Lock()
defer p.lk.Unlock()
// Filter out deals whose context has been cancelled
deals := make([]*pendingDeal, 0, len(p.pending))
for _, dl := range p.pending {
if dl.ctx.Err() == nil {
deals = append(deals, dl)
}
}
return &PendingInfo{
deals: deals,
publishPeriodStart: p.publishPeriodStart,
publishPeriod: p.publishPeriod,
}
}
// ForcePublishPendingDeals publishes all pending deals without waiting for
// the publish period to elapse
func (p *DealPublisher) ForcePublishPendingDeals() {
p.lk.Lock()
defer p.lk.Unlock()
log.Infof("force publishing deals")
p.publishAllDeals()
}
func (p *DealPublisher) Publish(ctx context.Context, deal market2.ClientDealProposal) (cid.Cid, error) {
pdeal := newPendingDeal(ctx, deal)