0

I have a web site (MVC5, C#5, .Net4.5) which I want to operate similarly to something like an airline flights site when checking out a product, as inventory is limited and specific.

For example: I select a flight, that flight is held for 10 minutes. If I finish reservation before 10 minutes, that flight is reserved for me and the hold obviously is removed.

If I instead just close my browser, what should I do to release that hold even if the user's session is gone before the timer is done?

The information is in an MSSQL table (productId, holdEnds[datetime]) as to when the hold should be released.


Is there any other way than a SQL job which would poll that table every minute for any holds that need to be released? I'd love to be able to schedule a piece of code to run at a specific datetime from within my controller.

Chris Emerson
  • 13,041
  • 3
  • 44
  • 66
DFTR
  • 861
  • 10
  • 30
  • Are you aware that the process running ASP.NET can die at any time. You need to use a proper scheduler, – Paulo Morgado Oct 02 '16 at 21:29
  • I am aware. That is the reason for my question. – DFTR Oct 02 '16 at 23:55
  • Do you have a suggestion for a "proper scheduler" as that would answer it – DFTR Oct 03 '16 at 00:29
  • SQL Server job, Windows Scheduled Task, etc. – Paulo Morgado Oct 03 '16 at 09:50
  • So how would I tell a SQL server job to start at a specific time in the future from my ASP.Net code? Since I mentioned SQL server job in the question, but my understanding is I can only have it "poll" the table at set intervals. – DFTR Oct 03 '16 at 15:55
  • I wouldn't recommend giving a website that level of permissions over the database server. What is usually done is having a job run at a pre determined schedule that check for work to be done. And, like you said, being a database, you put the information of what needs to be done in a table. – Paulo Morgado Oct 03 '16 at 23:32
  • Hi @DFTR We normally create console application for this type of scheduled services and put it in windows task scheduler to run after every half an hour or so depending upon requirement. This way you can add logging as well. – Murtaza Tahir Ali Oct 31 '16 at 22:35
  • I'm doing the same thing in a sql job that polls the table. I was just hoping maybe there was a more elegant solution than constantly running a job to check – DFTR Oct 31 '16 at 22:36

1 Answers1

0

There is a javascript event that is fire if the page is browsed away from, not sure if it will apply to the close event. Look at this SO Question and Answer or this Answer

On the other hand you can have either a windows service or console application (running via Task Scheduler) to release the data back after the time has lapsed.

For a solution I would look at a combination of checking if the browser has been close and a task checking the sql table to see if the stock needs returning back.

Community
  • 1
  • 1
Geek
  • 415
  • 4
  • 16