使用Hangfire进行自动付款处理

时间:2016-04-30 22:05:52

标签: mysql asp.net-mvc entity-framework owin hangfire

我刚刚发现了篝火。我已经成功安装了mysql存储版本。我想在以下场景中使用它: 每天凌晨12:01它应该触发带有OWIN和EF应用程序控制器操作的ASP.NET MVC5,该操作检查数据库并选择由于在相关日期处理的付款引用。该操作通过向支付处理提供商呈现API来结束。我的问题是,如果我的行动被称为" ProcessPayments"如何设置hangfire以每天重复此过程。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

以防有人在我问这个问题时需要像我一样的启动推送。使用Hangfire Mysql Storage,Identity 2,ASP.NET,MVC5,EF,C#,您可以在控制器中创建一个操作,如下所示,为该过程添加一个循环作业。

public ActionResult PDPayment(int id)
{                     
string cronExp = "1 12 * * *";
using (ApplicationDbContext db = new ApplicationDbContext())
{
var a = db.DDs.SingleOrDefault(a => a.DDId==id);
RecurringJob.AddOrUpdate(a.id+"-"+a.DDId+"_job", () => ProcessPayments(id), cronExp);
return new EmptyResult();
}    
}

然后为付款创建方法或逻辑。

 public static void ProcessPayments(int id)
       {
   eg fetch records with id
   create invoice
   process invoice- payment
   update records of payment
   send email
   redirect to success or failed page     
       }