active_fulfillment 3.2.1 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 804e3e5791d47c2869a62f774dcc13c0ca086fd8
4
- data.tar.gz: acc14cb632a432229594ed0de859026a71a778ea
3
+ metadata.gz: d288b33870248b76342ef2226467f4c782fc37cc
4
+ data.tar.gz: 545b5ad66e986c085c24accd94ce68e6a41c40d2
5
5
  SHA512:
6
- metadata.gz: ab2f0781d5aee8b146f740b754b8a7219f89509dd0219e0ebf490b1293b3d4009c67c3602039f1bbc897180f8f7ca0942efbdba3f8c74392c07eefc406ecc4b3
7
- data.tar.gz: 86a092f5142799e14d2d440319daa2381812bf53ed97f43300796c45eb1b69581dcf9d036406bff93f5c5fd92248af18c4e61a41ff6b7b77ae68c4e71b98fdd3
6
+ metadata.gz: 79a0204832b57d4609ff932eef6310e13c39e362469c1bd82e62a0e829eff49498641ccd736e19e1b961f718e70c40baa2216726850ad705f609409cc3c5a75b
7
+ data.tar.gz: 8217c752ca10dd4384c16c0cd81eb621b3ddc8f8442f43fd6b3db13b3f9376150171f1bfe5960f7a02f49619434ff42f6a754ed2f1952762206f5da62afccd50
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # ActiveFulfillment changelog
2
2
 
3
+ ### Version 3.2.2
4
+ - Add an option to retry Amazon requests upon getting a 503.
5
+
3
6
  ### Version 3.2.1
4
7
 
5
8
  - Allow truncating the Amazon response log.
@@ -110,12 +110,14 @@ module ActiveFulfillment
110
110
 
111
111
  def fetch_stock_levels(options = {})
112
112
  options[:skus] = [options.delete(:sku)] if options.include?(:sku)
113
- response = with_error_handling do
113
+ max_retries = options[:max_retries] || 0
114
+
115
+ response = with_error_handling(max_retries) do
114
116
  data = commit :post, 'FulfillmentInventory', build_inventory_list_request(options)
115
117
  parse_inventory_response(parse_document(data))
116
118
  end
117
119
  while token = response.params['next_token'] do
118
- next_page = with_error_handling do
120
+ next_page = with_error_handling(max_retries) do
119
121
  data = commit :post, 'FulfillmentInventory', build_next_inventory_list_request(token)
120
122
  parse_inventory_response(parse_document(data))
121
123
  end
@@ -429,10 +431,18 @@ module ActiveFulfillment
429
431
 
430
432
  private
431
433
 
432
- def with_error_handling
433
- yield
434
- rescue ActiveUtils::ResponseError => e
435
- handle_error(e)
434
+ def with_error_handling(max_retries = 0)
435
+ retries = 0
436
+ begin
437
+ yield
438
+ rescue ActiveUtils::ResponseError => e
439
+ if e.response.code == 503 && retries < max_retries
440
+ retries += 1
441
+ retry
442
+ else
443
+ handle_error(e)
444
+ end
445
+ end
436
446
  end
437
447
 
438
448
  def sleep_for_throttle_options(throttle_options, index)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module ActiveFulfillment
3
- VERSION = "3.2.1"
3
+ VERSION = "3.2.2"
4
4
  end
@@ -337,6 +337,17 @@ class AmazonMarketplaceWebServiceTest < Minitest::Test
337
337
  assert_equal 5259, response.stock_levels['GN-01-02A']
338
338
  end
339
339
 
340
+ def test_get_inventory_for_specific_skus_requests_correct_skus
341
+ requested_skus = ['GN-00-01A', 'GN-00-02A', 'GN-01-01A', 'GN-01-02A']
342
+ @service.expects(:commit).with(any_parameters) do |_method, _amazon_action, xml|
343
+ assert_equal xml['SellerSkus.member.1'], requested_skus[0]
344
+ assert_equal xml['SellerSkus.member.2'], requested_skus[1]
345
+ assert_equal xml['SellerSkus.member.3'], requested_skus[2]
346
+ assert_equal xml['SellerSkus.member.4'], requested_skus[3]
347
+ end
348
+ @service.fetch_stock_levels(skus: requested_skus)
349
+ end
350
+
340
351
  def test_get_inventory_multipage_missing_stock
341
352
 
342
353
  @service.expects(:ssl_post).with { |uri, query, headers|
@@ -488,6 +499,15 @@ class AmazonMarketplaceWebServiceTest < Minitest::Test
488
499
  assert !constructed_address[nil]
489
500
  end
490
501
 
502
+ def test_retry_on_error
503
+ retries = 5
504
+ http_response = build_mock_response(response_from_503, "", 503)
505
+ @service.expects(:ssl_post).raises(ActiveUtils::ResponseError.new(http_response)).times(retries + 1)
506
+
507
+ response = @service.fetch_stock_levels(max_retries: retries)
508
+ refute_predicate response, :success?
509
+ end
510
+
491
511
  private
492
512
  def build_mock_response(response, message, code = "200")
493
513
  http_response = stub(:code => code, :message => message)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fulfillment
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Fauser
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-21 00:00:00.000000000 Z
12
+ date: 2017-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport