0

I built a bidding website for a client in which a user posts an item and sets the auction duration. The item is first in Pending state until an admin approves it or after 12 hours have passed since the user first posts it. From then on, the item gets Published and other users can bid on it. Once the auction period is over, the item should be Closed and the highest bidder wins the item...

In addition to that, I need to send email notifications...

  • To the admin once a new item is posted.
  • To the winner once he wins an item.
  • To the item's owner once the auction is closed.
  • To the admin once an auction has been closed and there was a winner (i.e: people actually bid on it).

Currently what I'm doing is to call some method in my business layer which checks whether there are any pending items that have passed the 12 hours period to make them published, and whether there are published items that have passed their auction duration to close them. This method is called from several places such as the website's home page, the item's search page and others... This is actually causing me problems (Refer to this question). So I think it's worth finding an alternative solution that would help me get rid of all these issues that are most likely due to poor design.

  1. Should I centralize this by calling that method from one single place and sending the emails accordingly?
  2. Should I delegate this whole thing to some sort of scheduled task? In this case, what time-frame would be reasonable to run this task?
  3. Any other suggestions?
Community
  • 1
  • 1
Kassem
  • 8,116
  • 17
  • 75
  • 116

2 Answers2

1

Should I delegate this whole thing to some sort of scheduled task? In this case, what time-frame would be reasonable to run this task?

Yes, this seems like the best approach. Offload the email sending to a separate process than your ASP.NET MVC application. As far as the time-frame is concerned, this will depend on your business requirements. You may take a look at Quartz.NET which could be used as a task scheduling mechanism.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

You should definitely offload this to another process like a scheduled task or a service. You don't say how many users you currently have or how many are likely to be doing something at the same time, but if you find your userbase to be growing having loads of emails being sent out on a web request will eventually time out.

A separate task/service will also allow you greater control over what emails get sent and when.

Peter Monks
  • 4,219
  • 2
  • 22
  • 38
  • Thanks for pointing out that the web request might time out once my user-base grows. That's something I should definitely not take lightly. But does running the scheduled task like every 5 min make any sense? Or do scheduled tasks usually run once every day or something like that? – Kassem Feb 05 '12 at 17:40
  • It depends on how often you need to run this task, but many people have asked this question on SO before, take a look at these search results for answers: [http://stackoverflow.com/search?q=scheduled+task+vs+service](http://stackoverflow.com/search?q=scheduled+task+vs+service) – Peter Monks Feb 06 '12 at 09:26