func()

in pkg/providers/pricing/pricing.go [163:198]


func (p *Provider) updatePricing(ctx context.Context) {
	if ctx.Err() != nil {
		return
	}

	prices := map[client.Item]bool{}
	err := p.fetchPricing(ctx, processPage(prices))
	if err != nil {
		if ctx.Err() != nil {
			return
		}
		log.FromContext(ctx).Error(err, fmt.Sprintf("error fetching updated pricing for region %s, using existing pricing data, on-demand: %s, spot: %s", p.region, err.lastOnDemandUpdateTime.Format(time.RFC3339), err.lastSpotUpdateTime.Format(time.RFC3339)))
		return
	}

	onDemandPrices, spotPrices := categorizePrices(prices)

	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()
		if err := p.UpdateOnDemandPricing(ctx, onDemandPrices); err != nil {
			log.FromContext(ctx).Error(err, fmt.Sprintf("error updating on-demand pricing for region %s, using existing pricing data from %s", p.region, err.lastOnDemandUpdateTime.Format(time.RFC3339)))
		}
	}()

	wg.Add(1)
	go func() {
		defer wg.Done()
		if err := p.UpdateSpotPricing(ctx, spotPrices); err != nil {
			log.FromContext(ctx).Error(err, fmt.Sprintf("error updating spot pricing for region %s, using existing pricing data from %s", p.region, err.lastSpotUpdateTime.Format(time.RFC3339)))
		}
	}()

	wg.Wait()
}