0

Explanation:

I am developing a simple car business system and I have to implement the following feature:

  1. A very special car model is delivered to a shop. There are a lot of people on waiting list exactly for this model.
  2. When the car arrives the first client receives the right to buy it, he / she has 24 hours to use this opportunity.

I have a special state in the DB that determines if the user is: on waiting list (I have the exact position, as well) or can use opportunity to buy the car. Whenever the car arrives, I run a method that changes the state of the first client on waiting list. And here comes the problem:

Problem: The client can use his opportunity, during the 24 hours period. But I have to check at the end, if he/she has bought the car. For this reason, I have to schedule a method to run in 24 hours.

Possible solution: I am thinking about two things. First is using a job scheduler like Hangfire. The problem is that since I do not have any other jobs in my app, I do not want to include a whole package for such a small thing. Second is using making the checking method asynchronous and making the thread sleep for 24 hours before proceeding (I do not feel comfortable in working with threads and this is just an idea). I got the idea from this article. Keep in mind that more than one car can arrive in more than one shop. Does it mean that I should use many threads and how it is going to affect the performance of the system?

Question:

Which of the two solutions is better?

Is there another possibility that you can suggest in this particular case?

1 Answer 1

1

I agree. Importing a package for only one job if you aren't going to use it for many jobs is a little bit of overkill.

If you are running SQL server, I'd recommend writing a .NET console application to run on a schedule using the SQL Server Agent. (see image) If you have stored procedures that need to run, you also have the option to run them directly from the SQL job if for some reason you don't want to run them from your .NET application.

Since it sounds like you need this to run on a data driven schedule, you may consider adding a trigger to look for a new record in your database whenever that "special" car is inserted into the database. MSDN SQL Job using Trigger

enter image description here

I've done something similar to this where every morning, an hour prior to business hours starting, I run a .NET executable that checks the latest record in table A and compares it to a value in table B and determines if the record in table A needs to be updated.

I also use SQL Server to run jobs that send emails on a schedule based on data that has been added or modified in a database.

There are advantages to using SQL server to running your jobs as there are many options available to notify you of events, retry running failed jobs, logging and job history. You can specify any type of schedule from repeating frequently to only running once a week. enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I am running SQL Sever, but it is hosted on Azure and as far as I am concerned, I cannot use SQL Agent there. Is there a way to implement the idea with the console app without SQL Agent?
Ah, I see. In that case, you may look at the Task Scheduler in Azure. I am not an Azure expert, however from the description it looks like it's very similar to the Windows Task Scheduler (another handy tool on Windows Server). azure.microsoft.com/en-us/services/scheduler You'll just need to put all your logic in your application for job failures and be sure to log what you need to ensure that the job runs smoothly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.