How to force to Fail a Job?

Hello Odin,
Let me say you, you are doing a very good job with all this.

On another hand, I want to know, how to force to fail a job. This is because, I want to control if some process into my job are working or else, I want to get a Job as a Fail one.

Ex.

RecurringJob.AddOrUpdate("MyJob", () => SomeJob(), "0/10 * * * *");
RecurringJob.Trigger("MyJob");

public string SomeJob()
{
       try
       { 
            //DO MY VERY LONG PROCESS
            Return "Process Succesfully";
       }
       catch (Exception ex)
       {
           Return "I want to mark this Job as Fail in my dashboard";
       }                
}

or something like that…

Thanks in advance.

1 Like

Thank you, @danielrinf! To fail a job, just throw an exception from a job method. After that, an automatic retry attempt is made by default, but you can disable it by applying an explicit attribute:

[AutomaticRetry(Attempts = 0)]
public void SomeJob()
{
    throw new InvalidOperationException("This job will never succeed.");
}
1 Like