Skip to content
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

[FeatureRequest] support for queue per parameter value #2

Open
tylkomat opened this issue Aug 18, 2016 · 4 comments
Open

[FeatureRequest] support for queue per parameter value #2

tylkomat opened this issue Aug 18, 2016 · 4 comments

Comments

@tylkomat
Copy link

For my api /do/:something I would like to allow only one request per value of something.

For example:

  • request to /do/something gets through
  • second request to /do/something has to wait for first request to finish
  • request to /do/somethingElse gets through

This is a simple example. The values for something are unspecified values like uuids.

@alykoshin
Copy link
Owner

Hello,

The issue is that internally there is only one Queue object per middleware. Dynamic creation of queues is a bit more complex than it is now.

Also the question is how to define something, i.e. how to define which part of the route to be used to limit the request: /do/:something/:other/action

@tylkomat
Copy link
Author

tylkomat commented Aug 23, 2016

The parameters are already parsed in the request object. Limiting could be done by matching parameters from an option value to the request parameters. Active limit could become an object for example:

app.use(queue({ activeLimit: {limit: 2, params: ['something'] }));

To limit only a changing something and ignoring other. Meaning a different value for other will still land on the same queue if something didn't change.

app.use(queue({ activeLimit: {limit: 2, params: ['something', 'other'] }));

In this case there should be probably a different queue for any something and other combination.

When a queue is empty it can be destroyed to not take up too much memory for routes which may not be accessed any more.

I would not got into the complexity of setting different limits for different parameters.

@tylkomat
Copy link
Author

It should not used globally in this way, but as a per route middleware.

@tylkomat
Copy link
Author

I don't know what use case you had in mind when you created this middleware. My use case was to limit access to one route which involved creation of a limited number of database artifacts. There I can't allow any concurrency since noSQL databases do not allow transactions and for every request I have to check if the item can be created. In a worst case when only one item is left to create there could come 2 or more requests at the same time and each get the answer that it is fine to create. I could involve redis for that matter but I was looking for a simple approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants