Create a scheduled task that unreserves stock items based on how long ago they were reserved

49 Views Asked by At

On the site I am currently working on, we would like to reserve all items in a basket upon a user adding/removing an item to the basket.

At which point if the user makes no further additions or subtractions to his basket after a set period of time, the items will be unreserved.

I know this could be achieved by giving each stock quantity a DateTime of when it was last reserved (the last time the basket was updated) and refreshing that time on every basket update.

Then setting a scheduled task for very minute going through all stock quantities and if they are more than X old they can be unreserved and added back in to main stock.

Is this the best way to achieve this or is there a more elegant solution than a scheduled task.

I am using MVC , and Azure for hosting (which has a task scheduler, not that I have explored whether it can perform this sort of task)

2

There are 2 best solutions below

0
On BEST ANSWER

Implemented the solution i thought was possible (Giving each item a "Last Modified" field and then using azure task scheduler , ran an action that processed all those with a datetime outside of a certain range. )

Seems to work fine.

0
On

If you use your stock quantity DateTime value as flag, and put a DateAdd(...) in your stock selection filter to allow items that have aged back into stock back into your results you don't need to create a scheduled task to remove the DateTime value. There will be a trade-off in query performance because it's slightly more complex, but with fewer moving pieces you will have a less complex, and therefore more supportable approach.