gpt4 book ai didi

ruby - Ruby 中的速率限制 Shopify API 调用

转载 作者:太空宇宙 更新时间:2023-11-03 16:12:48 24 4
gpt4 key购买 nike

我在 Ruby 中使用 Shopify 的 shopify_api gem。

我正在从外部来源更新每个产品的成本和价格,但是我达到了 API 限制并收到了 429 Too Many Requests ( https://help.shopify.com/en/api/reference/rest-admin-api-rate-limits )。

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

我宁愿使用 X-Shopify-Shop-Api-Call-LimitRetry-After 中提供的数据,也不愿添加固定的 sleep.

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

最佳答案

Shopify 本身有一个 gem 可以帮助限制速率:https://github.com/Shopify/limiter .

关于ruby - Ruby 中的速率限制 Shopify API 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56932941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com