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.
- Should I centralize this by calling that method from one single place and sending the emails accordingly?
- 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?
- Any other suggestions?