使待处理的排队项目过期 [英] Expire pending queued items

查看:43
本文介绍了使待处理的排队项目过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,用户可以购买数量有限的活动门票.用户可以在我的网站上获得门票.一旦他们的购物车中有可用的票,他们将有固定的时间(5分钟)来完成交易.

I am building a site that users can buy a limited number of event tickets. The users can go on my site and get the tickets. Once they have available tickets in their cart, they will have a set amount of time(5 minutes) to complete the transaction.

如果他们在计时器到时之前完成了交易,则票据将从数据库可用性中永久删除.

If they complete the transaction before the timer is up the tickets are permanently removed from the database availability.

如果他们在5分钟前仍未完成交易,那么他们的分配将重新排入队列,以供公众订购.

If they don't complete the transaction before the 5 minutes then their allotment gets put back into the queue for the public to order from.

我的问题是,如果用户未在5分钟内完成交易,将这些物品放回公共队列的最佳方法是什么?请记住,用户只能关闭网站,因此后端永远不会意识到这一点.我的想法是,当用户将项目放入购物车中时,后端应将其放入数据库中的集合中.然后,当用户完成将由支持者清理的交易时,如果用户关闭浏览器或未及时完成交易,则后端将有一个CRON作业,该作业每1分钟运行一次以放置未付款的交易回到常规队列.

My question is what is the best method of putting these items back in the public queue if the user doesn't complete the transaction before the 5 minutes is up? Remember the user could just close the website so the backend would never be aware of that. My thought is that when a user puts the items in their cart the backend should put that into a collection in the db. Then when the user completes the transaction that will be cleaned up by the backed.IF the user closes the browser or doesn't complete the transaction in time then the backend would have a CRON job that runs every 1 minute to put un-paid transactions back into the general queue.

CRON工作方法是最佳途径吗?到目前为止,我已经想出了所有这些,但是想知道是否有更好的方法吗?

Is the CRON job method the best route? That's all I've come up with so far but was wanting to know if there was a better way?

推荐答案

您可以使用 Cloud Tasks 回调到HTTP函数一个特定的时间.该函数可以执行到期.

You can use Cloud Tasks to schedule a callback to an HTTP function at a specific time. That function can perform the expiration.

或者,您可以定期检查要使用计划功能执行的工作,但是您必须接受计时的粒度最多可以偏离标记的一分钟.

Or, you can periodically check for work to be done with a scheduled function, but you'll have to accept that the granularity of timing will be up to one minute off the mark.

这篇关于使待处理的排队项目过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆