acts_as_queue
<img src=“
” alt=“Gem Version” /> <img src=“travis-ci.org/matthewl/acts_as_queue.png?branch=master” alt=“Build Status” /> <img src=“
” alt=“Dependency Status” />
acts_as_queue is a gem for ActiveRecord that allows you to turn any of your ActiveRecord models into a queue.
acts_as_queue provides you with methods to simplify using your ActiveRecord as a queue. The two key methods it provides are Push and Pop.
Push is used when you want to add an item to your queue. Pop is used when you need to process or remove the earliest item from your queue.
Using the default unbounded queue
class Post < ActiveRecord::Base
acts_as_queue
end
# Pushing new posts onto the queue.
Post.push :name => "Hello World"
Post.push :name => "Using Rails"
# Popping the item at the front of the queue.
Post.pop
Using a bounded queue
class Message < ActiveRecord::Base
acts_as_queue :size => 10
end
# Pushing 20 new messages onto the queue.
(1..20).each { |i| Message.push :description => "Message #{i}" }
Message.count # Just 10 messages on the queue