Ruby中Shopify API调用的速率限制

Ruby中Shopify API调用的速率限制,ruby,shopify,Ruby,Shopify,我在Ruby中使用Shopify的Shopify\u apigem 我正在从外部来源更新每个产品的成本和价格,但是我达到了API限制,并且收到了太多的请求 我如何编辑以下内容以遵守API限制 我宁愿使用X-Shopify-Shop-Api-Call-Limit和中提供的数据,也不愿添加固定的睡眠 products = ShopifyAPI::Product.find(:all, :params => {:limit => limit}) products.each do |prod

我在Ruby中使用Shopify的
Shopify\u api
gem

我正在从外部来源更新每个产品的成本和价格,但是我达到了API限制,并且收到了太多的请求

我如何编辑以下内容以遵守API限制

我宁愿使用
X-Shopify-Shop-Api-Call-Limit
中提供的数据,也不愿添加固定的
睡眠

products = ShopifyAPI::Product.find(:all, :params => {:limit => limit})

products.each do |product|
                variant = ShopifyAPI::Variant.find(product.variants.first.id)

                variant.price = price
                variant.save

                inventoryitem = ShopifyAPI::InventoryItem.find(product.variants.first.inventory_item_id)

                inventoryitem.cost = cost
                inventoryitem.save
        end
end

最简单的方法是使用Monkeypatch ActiveResource。这是一份为你做所有工作的回购协议


Shopify自身有一块宝石,可以帮助您降低利率:

我宁愿使用X-Shopify-Shop-Api-Call-Limit中提供的数据 然后重试,而不是添加固定睡眠

政府是这样做的。它看起来是在
标题后重试,但使用固定睡眠。没办法睡觉。还有什么办法等呢

它不做任何“猴子修补”。这很好。猴子修补可能会在某个时候导致问题

与代码一起使用

products = ShopifyAPIRetry.retry { ShopifyAPI::Product.find(:all, :params => {:limit => limit}) }
products.each do |product|
  variant = ShopifyAPIRetry.retry { ShopifyAPI::Variant.find(product.variants.first.id) }

  variant.price = price
  ShopifyAPIRetry.retry { variant.save }

  inventoryitem = ShopifyAPIRetry.retry { ShopifyAPI::InventoryItem.find(product.variants.first.inventory_item_id) }

  inventoryitem.cost = cost
  ShopifyAPIRetry.retry { inventoryitem.save }
end

到处都要调用
重试
并没有那么好。你可以把一些地方合并成一个电话

你用过那颗宝石吗?它工作得好吗?你有没有什么例子可以作为要点或其他什么东西发布?这看起来很有趣,但也有点模糊,它是如何与活动资源交互的