Temporary reserve

Asked

Viewed 56 times

1

I have the following problem:

I am creating a booking application and as soon as a user clicks on a product to book, this product should be removed from the list of available temporarily for him to finalize the reservation. If it does not finish in 5 minutes, this product is available again.

I managed to make this previous reservation by updating the 'status' column of the product, but I have no idea how to make it back to availability after 5 minutes.

Can someone help me?

  • You can use a Cron to re-update all items that have been booked and not confirmed in the last 5 minutes and return them to available status. Include your code to the question.

  • 1

    I would use a scheduled event in mysql that runs every 5 minutes and do a validation according to the scheduling time and the current time.

1 answer

0

You can use the EVENT of MySQL, for this first need to activate the feature in your database:

SET GLOBAL event_scheduler = ON;

Create the event:

CREATE EVENT mudar_status
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 MINUTE
DO
UPDATE tabela_status
SET status = 1
WHERE status = 0
  • 1

    And if the purchase is made, as cancels the event?

  • This you determine in WHERE, when the reservation is made, for example, vc puts a status = 2, and when confirmed status = 0, understand? But there you change, before creating the event, which status is the reservation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.