2016-04-07 6 views
0

私は、ユーザーがWebサイトにサインアップするたびに電子メールを送信するASP.NETアプリを持っています。私は電子メールを送るためにジョブと郵便を管理するためにハングファイアを使用しています。ASP.NETでHangfireを使用してジョブを失敗に設定しますか?

これは、すべての素晴らしい作品が、ここでの事です:

私はスーパーユーザがAPPは、ジョブを削除する前に電子メールを送ることができますどのように多くの時間変更したいです。ここで

は私のコードは、なぜ、それを自動的に処理するために属性を追加しない

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); 
      } 
     } 
    } 

答えて

0

ですか?

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

または、AutommaticRetryAttributeクラスを模倣する独自の属性を作成できますが、それをどのように扱うことができますか?

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

+0

まあ、ポイントは私が試行回数を変更することが許可されるには、スーパーユーザーをしたいです。だから、私はそれを私のやり方でやりたいのです。 – ggderas

+0

右。 AutomaticRetryAttributeがどのように行われたかを見直して自分の条件に置き換えることで、独自のAutomaticRetry属性を作成できますか? –

関連する問題