Specify retry attempts at enqueue

I’m looking for a way to specify the retry attempts when I enqueue my job. I know it’s possible with an attribute on the job class, but I need it to be variable, i.e. I don’t know at compile time what the number of retries will be.

I’ve tried this:

var client = new BackgroundJobClient(JobStorage.Current);
client.RetryAttempts = retryAttempts;
client.Enqueue<MyJob>(x => x.DoWork());

And this:

var filters = new JobFilterCollection();

foreach (var filter in GlobalJobFilters.Filters)
{
    filters.Add(filter.Instance);
}

filters.Add(new AutomaticRetryAttribute { Attempts = retryAttempts });

var client = new BackgroundJobClient(JobStorage.Current, filters);

client.Enqueue<MyJob>(x => x.DoWork());

But it still seems to retry 10 times. So what is the best way to specify the number of retry attempts at the moment we enqueue our job?