简体   繁体   中英

Expire pending queued items

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM