Z
Z
ZloyDyadka2015-06-08 21:55:43
JavaScript
ZloyDyadka, 2015-06-08 21:55:43

How to organize the removal of overdue orders?

Hello, the problem is this - it is possible to reserve an item for a certain time, and there is a function that shows the status of this item. The bottom line is that the status display should always be true, i.e. we need items that are not marked as "In Progress" to be marked with the status N if the reservation start time has already passed.
We are sampling all the services first, and they should already have a corresponding status - there are free items / no.
I see only two solutions to this problem:
1. For each found service, run a function that will go through all its reserved items
2. Create a setTimeout for the created order, which, at the expected start of its reservation, will have to check the status
The first method seems to me more labor-intensive, because. you have to do too many things.
But the second one has a lot of nuances, this is - if the server crashes, then all these timeouts will disappear, and it will probably take up a lot of memory.
Looking forward to your suggestions, thanks in advance :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2015-06-09
@ZloyDyadka

I think you are reinventing the wheel. You make a separate field in the database with the reservation time. setTimeout periodically runs through the database and checks the difference in the creation time and some delay time (or generally set the delay date and simply compare it with the current one). Unpurchased marks back available. Even if the server is restarted, the next check will reveal old orders.

V
Valentin Dubrovsky, 2015-06-09
@matroskin13

cron

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question