Get Job description from dashboard through HangFire Api


#1

Hello,

I need to get the job description through the api if it’s possible that is shown in the dashboard under “Job”.

In my case it’s “Transfering credit card transactions”. I set it through the attribute displayName [DisplayName("{0}")].

I have a parameter for the message but I want make it more generic, I don’t want to have to send the first parameter as a message in all my methods so I can get them through job.Args[index]

I have looked through the hangfire documentation and can’t find out how to get this information without using job.args


#2

When we have a complex object as parameter (such as class), override ToString() method to return required display name;

 public class DocumentInfo
{
    public string Title{ get; set; }
 
    public override string ToString()
    {
        return Title;
    }
} 

//Job method
[DisplayName("ProcessDocument {0}")]   //{0} will call ToString of complex object
void ProcessDocument(DocumentInfo info)
{
     //Logic
}