Job Quotas (Per user)

Hello,

I have a question which is more about the usage of Hangfire in a specific kind of scenario.

The scenario can be generalized as being where you have an API and users of this API can schedule tasks. The users have quotas (I.e. Per API key) which control the maximum number of concurrent tasks.

By this I mean a user might have a “quota” (Maybe this is the wrong word) of 5 concurrent tasks, but may queue 15 tasks. These would be run 5-at a time until they have all completed. This should not affect other users who have their own quota.

What is the easiest way of implementing this sort of thing ? I’ve done it in the past (Without using Hangfire) by using an SQL serialisable transaction to select the next job by counting the number of currently executing jobs per user and then selecting the next job from a user who hasn’t exceeded their limit, but this is far from scalable.

There must be many implementations of this scenario but I haven’t been able to find examples of how others have done this.

Thanks,
-Andrew.