Class: Webhookdb::Replicator::AwsPricingV1::ServiceBackfiller

Inherits:
Backfiller
  • Object
show all
Includes:
Backfiller::Bulk
Defined in:
lib/webhookdb/replicator/aws_pricing_v1.rb

Defined Under Namespace

Classes: UrlStreamer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Backfiller::Bulk

#dry_run?, #flush_pending_inserts, #handle_item, #pending_inserts, #remote_key_column_name

Methods inherited from Backfiller

#_fetch_backfill_page_with_retry, #backfill, do_retry_wait, #handle_item, #max_backfill_retry_attempts, #wait_for_retry_attempt

Constructor Details

#initialize(replicator, service_code, currency_code, effective_date) ⇒ ServiceBackfiller

Returns a new instance of ServiceBackfiller.



193
194
195
196
197
198
199
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 193

def initialize(replicator, service_code, currency_code, effective_date)
  @replicator = replicator
  @service_code = service_code
  @currency_code = currency_code
  @effective_date = effective_date
  super()
end

Instance Attribute Details

#currency_codeObject (readonly)

Returns the value of attribute currency_code.



191
192
193
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 191

def currency_code
  @currency_code
end

#effective_dateObject (readonly)

Returns the value of attribute effective_date.



191
192
193
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 191

def effective_date
  @effective_date
end

#pricingObject (readonly)

Returns the value of attribute pricing.



191
192
193
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 191

def pricing
  @pricing
end

#replicatorObject (readonly)

Returns the value of attribute replicator.



191
192
193
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 191

def replicator
  @replicator
end

#service_codeObject (readonly)

Returns the value of attribute service_code.



191
192
193
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 191

def service_code
  @service_code
end

Instance Method Details

#conditional_upsert?Boolean

Returns:

  • (Boolean)


204
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 204

def conditional_upsert? = true

#fetch_backfill_page(pagination_token) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 206

def fetch_backfill_page(pagination_token, **)
  # Fetch a page of price lists ARNs for this service
  list_req = self.replicator.with_pricing_client do |pricing|
    pricing.build_request(
      :list_price_lists,
      {
        currency_code:,
        effective_date:,
        max_results: 100,
        next_token: pagination_token,
        service_code:,
      },
    )
  end
  arns_to_fetch = []
  list_req.send_request({}).each do |list_resp|
    # We need to enumerate everything at once. Because inserting can take so long
    # that next_tokene xpires.
    list_resp.price_lists.map do |pl|
      arns_to_fetch << pl.price_list_arn
    end
  end

  # To avoid having to process the entire JSON file into an array of thousands of items,
  # process rates one-by-one. We may have huge memory for the JSON file itself, but won't need it
  # to store the hashes we'll them bulk insert. This is also more responsive because we'll be upserting
  # pages as we have them available, rather than only after everything is converted.
  iter = UrlStreamer.new(self.replicator, arns_to_fetch)
  # next_token is nil when we have processed all price list files for the service.
  return iter, nil
end

#prepare_body(_body) ⇒ Object



202
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 202

def prepare_body(_body) = nil

#upsert_page_sizeObject



201
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 201

def upsert_page_size = 500

#upserting_replicatorObject



203
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 203

def upserting_replicator = @replicator