PcQueues
A Queue Management Gem with Redis backing.
Copyright (c) ProctorCam Inc. 2014 All rights reserved
Installation
Dependency: Rails, Database, PubNub
Add the following to your Gemfile
gem 'pc-queues', :git => 'git@gitlab.proctorcam.com:proctorcam-development/pc-queues', :branch => 'develop'
Run the install and migration generators
> rails g pc_queues:install
> rails g pc_queues:migration
> rake db:migrate
Update the initializer in config/initializers/pc_queues.rb to initialize the PubNub instance used.
That's it - you're done setting up.
Getting Started
Once you've got the gem setup. You'll designate Models as Enqueable and as Queue owners. Classes that are Enqueueable
can be enqueued and dequeued from a Queue Classes that are Queue owners can have has_one and has_many relationships to
Queues.
Queues are setup for single table inheritance, so you can derive from Queue to handle Class specific behavior.
An ActiveRecordClass can be both a Queue owner and Enqueable.
Setting Up to be a Queue Owner
require 'pc_queues'
class MyQueue < PcQueues::Queue
end
class MyModel < ActiveRecord::Base
include ACTS_AS_QUEUE_OWNER
has_many_queues_as :my_queues
has_one_queue_as :fast_stuff, class_name: 'MyQueue'
end
Setting Up to be a Queue Item
require 'pc_queues'
class MyModel < ActiveRecord::Base
include ACTS_AS_ENQUEABLE
end
Queue Manipulation
model = MyModel.create attr1: value1
model.create_fast_stuff attr1: value1
model.my_queues.create attr1: value1
model.fast_stuff.enqueue my_acts_as_enqueuable_object
my_acts_as_enqueuable_object = model.fast_stuff.dequeue
length = model.fast_stuff.length