简体   繁体   English

根据时间限制更改项目的状态

[英]Changing the status of an item based on time constraints

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. 该项目处于待处理状态,直到管理员批准该项目或自用户首次发布后12小时后。 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 (ie: 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. 目前我正在做的是在我的业务层中调用一些方法来检查是否有任何已经超过12小时的待处理项目才能发布它们,以及是否有已发布的项目已经超过其拍卖持续时间以关闭它们。 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? 还有其他建议吗?

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. 将电子邮件发送卸载到与ASP.NET MVC应用程序不同的进程。 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. 您可以查看Quartz.NET ,它可以用作任务调度机制。

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. 您没有说明您目前有多少用户或有多少可能同时做某事,但如果您发现您的用户群不断增长,在Web请求中发送大量电子邮件将最终超时。

A separate task/service will also allow you greater control over what emails get sent and when. 单独的任务/服务还可以让您更好地控制发送的电子邮件和时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM