Can I configure options for each job during enqueuing?

For example, for some jobs I want it to be failed in case of any exception, and some jobs I need to have the auto retry feature. I think the Enqueue method should have overloads that take some sort of configuration option parameter?

1 Like

You can decorate your method using the AutomaticRetryAttribute

here’s an example :

[JobDisplayName("Method with argument {0}")]
[AutomaticRetry(Attempts = 5, DelaysInSeconds = new int[] { 5, 10, 15, 20, 25 })]
Task Method(string parameter, PerformContext context);

Thanks for the reply. I’m aware of the auto retry feature. And I’d expect some more advanced configuration options for each job.

1 Like

Did you figure this out? Since my job implementation happens in an application layer, I don’t want a hangfire dependency to sit there. Therefore I cannot use the annotations. I think hangfire does not persist any retry settings to the job store. The annotations are evaluted when the job runs. This is why the API e.g. AddOrUpdate does not provide such functionality.