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
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:
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.
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.