我已经为 shopify 创建了一个 mvc web api 2 webhook:
public class ShopifyController : ApiController
{
// PUT: api/Afilliate/SaveOrder
[ResponseType(typeof(string))]
public IHttpActionResult WebHook(ShopifyOrder order)
{
// need to return 202 response otherwise webhook is deleted
return Ok(ProcessOrder(order));
}
}
Where ProcessOrder
循环处理订单并将详细信息保存到我们的内部数据库中。
但是,如果该过程花费的时间太长,则 webhook 会再次调用 api,因为它认为它已失败。有什么办法可以退回ok
先响应然后再处理?
有点像当您在 mvc 控制器中返回重定向并可以选择在重定向后继续处理其余操作时。
请注意,我始终需要返回 ok 响应,因为 Shopify 尽其所能决定在失败 19 次时删除 Webhook(处理时间过长将被视为失败)
我已经通过使用异步运行处理来解决我的问题Task
:
// PUT: api/Afilliate/SaveOrder
public IHttpActionResult WebHook(ShopifyOrder order)
{
// this should process the order asynchronously
var tasks = new[]
{
Task.Run(() => ProcessOrder(order))
};
// without the await here, this should be hit before the order processing is complete
return Ok("ok");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)