Expire pending queued items

爱⌒轻易说出口 提交于 2020-03-25 13:43:42

问题


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.

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.

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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/59055431/expire-pending-queued-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!