Ali Zeinali
Ali Zeinali

Reputation: 571

Scheduling in Asp.net Mvc and web api

I'm working on a project with Asp.net MVC 5 and web api and SQL Server. I should implement a functionality that required scheduling.

I have some users in this system that every user can register an order and I save order information in the database.

Problem: for each order that has been registered in system after 2 minutes, I should send a message to his owner and notify him about his order status.

How should I check each order status 2 minutes after it has been registered?

Should I schedule a task per order that has been registered? (it could be more than 500 order per sec so I don't thinks it is a good solution)

I want a solution to handle this with a good performance.

Upvotes: 2

Views: 2404

Answers (2)

LearningDesires
LearningDesires

Reputation: 3

another solution could be ,each time order is saved write it to a text file on server,and at the same time add watch to notify you the text file is changed ,which will trigger your service to send message

Upvotes: 0

Bert Sinnema
Bert Sinnema

Reputation: 329

Your best solution here is Hangfire

Hangfire is built for these kind of challenges. It really doesn't matter how many jobs you have. After you have configured Hangfire you can simply pass methods to the queue. You can also delay the execution with a TimeSpan

BackgroundJob.Schedule(
() => Console.WriteLine("Delayed!"),
TimeSpan.FromMinutes(2));

You can even chain jobs, very handy if you have multiple steps in your order process:

BackgroundJob.Schedule(() => {

    SomeProcessToComplete();

},TimeSpan.FromMinutes(2));

static void SomeProcessToComplete(){

     //after code runs add another job to the queue
    BackgroundJob.Schedule(
    () => Console.WriteLine("Delayed!"),
    TimeSpan.FromMinutes(2));
}

Upvotes: 2

Related Questions