HangfireIO / HangfireIO/Hangfire
Retry options per job creation, not per job type
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
I would love it if Hangfire would support configuring the maximum number of retries per actual job, not per job type. I know I can add an attribute to my job class, but I would like to provide it as an option when enqueuing the job. (I already posted about this in [the forum](https://discuss.hangfire.io/t/specify-retry-attempts-at-enqueue/11429))
So instead of doing this:
```
[AutomaticRetry(Attempts = 5)]
public class MyJob{}
```
I want to be able to do something like this:
```
BackgroundJob.Enqueue(x => x.Execute(), new BackgroundJobOptions { Retries = 5 });
BackgroundJob.Enqueue(x => x.Execute(), new BackgroundJobOptions { Retries = 2 });
```
This would create two jobs. One would be retried 5 times, the other only 2 times.
I've taken a look at the code and it doesn't seem very easy. But with some pointers, I would be willing to create a PR. I think it might require a change in the data storage, to hold the options per job. Possibly, the `BackgroundExecutionOptions` class could be used.
But first: is this something you feel would be an improvement?
Contributor guide
Research direction
Start by tracing BackgroundJob.Enqueue and AutomaticRetry, then inspect the mentioned BackgroundExecutionOptions class and how job data is stored. The change is complete when two otherwise identical enqueued jobs can retain and apply different retry limits, such as 5 and 2, without relying on a job-type attribute.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100