2016-04-07 9 views
0

Kullanıcı web sitesinde her kaydolduğunda e-posta gönderen bir ASP.NET uygulamasına sahibim. E-posta göndermek için işleri yönetmek ve posta göndermek için hangfire kullanıyorum.Bir işi ASP.NET ile Hangfire kullanarak başarısız hale getirecek şekilde ayarlayın?

Ben süper APP işi silmeden önce e-posta gönderebilir kaç kez değiştirmek istiyorum: Hepsi burada harika çalışır, ancak

şey.

İşte

public static void WelcomeUser(DBContexts.Notifications not) 
    { 
     try{ 
      var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails")); 
      var engines = new ViewEngineCollection(); 
      engines.Add(new FileSystemRazorViewEngine(viewsPath)); 

      Postal.EmailService service = new Postal.EmailService(engines); 

      WelcomeUserMail welcomeUserMail = new WelcomeUserMail(); 
      welcomeUserMail.To = not.ReceiverEmail; 
      welcomeUserMail.UserEmail = not.ReceiverEmail; 
      welcomeUserMail.From = BaseNotification.GetEmailFrom(); 

      service.Send(welcomeUserMail); 
     } 
     catch(Exception e) 
     { 
      DBContexts.DBModel dbModel = new DBModel(); 
      DBContexts.Notifications notificacionBD = dbModel.Notifications.Find(not.NotificationID); 

      notificacionBD.Status = false; 
      notificacionBD.Timestamp = DateTime.Now; 
      notificacionBD.Error = e.Message; 

      int numberOfRetriesAllowed = ParameterHelper.getNumberOfRetriesAllowed(); 

      if (notificacionBD.Retries > numberOfRetriesAllowed) 
      { 
       //In this case Hangfire won't put this job in the failed section but rather in the processed section. 
       dbModel.SaveChanges(); 
      } 
      else 
      { 
       notificacionBD.Retries++; 
       dbModel.SaveChanges(); 

       throw new Exception(e.Message); 
      } 
     } 
    } 

cevap

0

Neden sadece otomatik olarak işlemek için özelliklerini eklemek kod bu?

[AutomaticRetry(Attempts = 10, LogEvents = true, OnAttemptsExceeded = AttemptsExceededAction.Delete)] 
public void MyTask(){ 
    //doing stuff 
} 

Ya da sadece AutommaticRetryAttribute sınıfını taklit kendi özelliğini yapabilir ama istediğin nasıl başa?

https://github.com/HangfireIO/Hangfire/blob/a5761072f18ff4caa80910cda4652970cf52e693/src/Hangfire.Core/AutomaticRetryAttribute.cs

+0

Hayır, demek ben süper kullanıcı deneme sayısını değiştirmek için izin istemeniz. Bu yüzden benimle başa çıkmak istiyorum. – ggderas

+0

Sağ. AutomaticRetryAttribute'un nasıl yapıldığını gözden geçirip kendi şartlarınızla değiştirerek kendi AutomaticRetry özniteliğinizi oluşturabilirsiniz. –

İlgili konular