Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add 1 second throttle to avoid Amazon rate limiter

  • Loading branch information...
commit c07d1eef7016203a01c9e67c5d10f7d8deb2ef89 1 parent 6c1ce6c
Bill Lipa wlipa authored
Showing with 4 additions and 1 deletion.
  1. +2 −0  app/models/amazon_fulfillment.rb
  2. +2 −1  app/models/fulfillment.rb
2  app/models/amazon_fulfillment.rb
View
@@ -113,6 +113,7 @@ def ensure_shippable
# Runs inside a state_machine callback. So throwing :halt is how we abort things.
def fulfill
Fulfillment.log "AmazonFulfillment.fulfill start"
+ sleep 1 # avoid throttle from Amazon
ensure_shippable
num = @shipment.number
addr = address
@@ -144,6 +145,7 @@ def fulfill
# Returns the tracking number if there is one, else :error if there's a problem with the
# shipment that will result in a permanent failure to fulfill, else nil.
def track
+ sleep 1 # avoid throttle from Amazon
resp = remote.fetch_tracking_raw(@shipment.number)
Fulfillment.log "#{resp.params}"
# This can happen, for example, if the SKU doesn't exist.
3  app/models/fulfillment.rb
View
@@ -33,6 +33,7 @@ def self.process_ready
# a lock over a third party remote transaction which might be slow.
s = Shipment.find(sid, :lock => true)
if s && s.state == "ready"
+ log "request ship for #{s.id} at #{Time.now}"
s.ship
else
log "skipping ship for id #{sid} : #{s} #{s.try(:state)}"
@@ -54,7 +55,7 @@ def self.process_shipped
Shipment.fulfilling.each do |s|
begin
tracking_info = if s.tracking.blank?
- log "querying tracking status for #{s.id}"
+ log "querying tracking status for #{s.id} at #{Time.now}"
service_for(s).track
else
log "preexisting tracking status for #{s.id} - #{s.tracking}"
Please sign in to comment.
Something went wrong with that request. Please try again.