Add job filter at runtime when creating job

job-filters
Tags: #<Tag:0x00007f69fce6f308>

#1

Hi, I want to let the user configure the number of automatic retries when scheduling a job.
How can I do this? The only way I know of is to add an attribute to the method, but it can’t be changed at runtime.
Is it possible to add custom filters when scheduling a job?


#2

Yes, there are some posts on the forum as is on this.

Not sure if there is one that does specifically this but creating custom filter attributes is quite easy once you wrap your mind around the basic idea. You could google for instance ‘hangfire mutex attribute’ and you should see a sample custom filter from Odinserj himself as a gist.

Or you could start with this forum post Automatic retries - how to manually configure the time between retries which also should give you a good starting point. Although this example is a bit more complex as it also shows how to remove the built in automatic retry filter so it does not interfere with the ‘custom’ one.