feat: add methods to list pending deals and force publish
This commit is contained in:
parent
dc6392db49
commit
4676fd6753
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user