我有一个新客户 Webhook,每当创建新客户时都会多次触发该 Webhook。我已通过 API 连接确认我的测试商店中仅存在一个 Webhook。
def new_customer_callback <<< ---- gets called multiple times
# here I create a customer in my app,
# but the customer has some custom validations that take a while
head :ok
end
我的想法是,也许 webhook 会一直触发,直到 head :ok 返回。因此,由于我的customers.create 自定义验证花费了很长时间,因此 webhook 被多次触发。
这是正确的吗?有什么好方法可以避免这种情况呢?我不想让我的应用程序因运行多个不必要的回调而陷入困境
最佳答案
Shopify 在重试请求之前有 5 秒的超时时间。
如果您的应用需要时间来处理请求,您需要将请求添加到队列中,立即响应请求,然后稍后处理请求。您还可以在不同的线程中或并行运行它,但您需要确保 Shopify 尽快收到响应以避免超时。
关于ruby-on-rails - Shopify 和 Rails : Webhook being fired multiple times,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33047374/