UserQ: Simple User Queues for Rails
UserQ allows you to very quickly integrate awesome user-based queues into your Rails application. Many large ticketing websites such as Ticketmaster use queues as a means of user experience.
queue = UserQ::Queue.new(capacity: 50) ## Can we enter the queue? if queue.enter_into_queue? entry = queue.enter # They have a place in the queue. Sell them a ticket! else # No place in queue. Run this block again after n seconds. end # Default expiry: 180 seconds puts entry.expires # => 180 sleep(5) puts entry.expires # => 175
How does it work?
Tell it how much you capacity you have (i.e. how many available tickets are left) and then UserQ does its beautiful magic. Some of the questions you can ask UserQ:
- How many "people" are in the queue?
- When does the current users spot in the queue expire?
- When do you think another spot in the queue will open? (i.e. average wait time)
- Can I extend/shorten the current users spot in the queue?
Install the gem: $ gem install userq Install the database model (automatically migrates): $ rails generate userq:install You're all setup!
See the full documentation on the Wiki to see what you can do with UserQ.
- Lots of more awesome looking tests
- Develop the UserQ Wiki
- Assign queue places in a chronological order (first into queue = first entry) instead of randomly
- 25/12/13: Fixed bug in using custom data (and tests added for it)
- 23/12/13: The initial version
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.