Skip to content

Retry options per job creation, not per job type #2572

@petermorlion

Description

@petermorlion

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)

So instead of doing this:

[AutomaticRetry(Attempts = 5)]
public class MyJob{}

I want to be able to do something like this:

BackgroundJob.Enqueue<MyJob>(x => x.Execute(), new BackgroundJobOptions { Retries = 5 });
BackgroundJob.Enqueue<MyJob>(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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions