-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rate Limiting #375
Comments
What exactly do you mean by "rate limiting"? |
@azygis Sorry for not elaborating. I refer to the Concurrency and Rate Limiting features of the Personally, I'd love to have a feature to limit number of concurrent jobs for a specific argument. For instance, I want to have at most 10 concurrent jobs running for a specific user. Something like this would be extremely useful: [Limit(user_id, concurrency=10)]
public void Process(Guid user_id, string data) { ... } |
Looks like the library is behind a paid NuGet repository which I personally won't buy. This can only be implemented by whoever has access to it.
Not exactly sure what that means either. There is no technical documentation for community storage maintainers, as far as I can see. |
You can implement it with a client filter. I don't think it should be part of Hangfire.PostgreSql. But rather a dedicated package. Here is a simplified implementation I use. It does not require any storage specifics feature. I hope it will help you. public class MyCustomFilter(IServiceProvider _serviceProvider) : IClientFilter
{
public void OnCreating(CreatingContext filterContext)
{
// JobStorage.Current can be used if you don't want IOC
var jobStorage = _serviceProvider.GetRequiredService<JobStorage>();
var monitoringApi = jobStorage.GetMonitoringApi();
bool shouldCancel = /* custom logic */;
if (shouldCancel)
{
filterContext.Canceled = true;
}
}
public void OnCreated(CreatedContext filterContext) { }
}
// Setup
.AddHangfire((sc, config) => config.UseFilter(new DeDuplicateFilter(sc))); |
@latop2604 That might work! Do you by any chance know how I could reschedule / delay the job by a few minutes, instead of cancelling it? |
Not sure but something like that could work public void OnCreated(CreatedContext filterContext)
{
var backgroundJobClient = _serviceProvider.GetRequiredService<IBackgroundJobClient>();
var scheduledState = new ScheduledState(DateTime.UtcNow.AddDays(7));
backgroundJobClient.ChangeState(filterContext.BackgroundJob.Id, scheduledState, null);
} I tried to find a way to do it in |
Rate limiting on Hangfire.PostgreSql would be a great feature, and it would be extremely useful to me.
I understand the limited resources on this project, but I wonder what it would take to implement this?
I am not familiar with any Hangfire codebase, but given proper guidance, I'd be willing to try (helping) implement it.
Kind regards,
Jan
The text was updated successfully, but these errors were encountered: