Permalink
Browse files

initial commit of cassandra-queue gem code

  • Loading branch information...
0 parents commit d3e90fbb847e8f87bda3674e0d23e9a12df3ab06 @jbhat jbhat committed Apr 3, 2012
Showing with 137 additions and 0 deletions.
  1. +5 −0 Gemfile
  2. +19 −0 LICENSE
  3. +1 −0 README.md
  4. +20 −0 Rakefile
  5. +1 −0 TODO
  6. +34 −0 cassandra-queue.gemspec
  7. +54 −0 lib/cassandra-queue.rb
  8. +3 −0 lib/cassandra-queue/version.rb
@@ -0,0 +1,5 @@
+source "http://rubygems.org"
+source "http://gems.sv2"
+
+# Specify your gem's dependencies in your gemspec
+gemspec
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Ooyala, Inc.
+
+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.
@@ -0,0 +1 @@
+WRITE ME
@@ -0,0 +1,20 @@
+require "bundler"
+require "rake/testtask"
+
+require File.join(File.dirname(__FILE__), "lib", "cassandra-queue", "version")
+
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = Dir.glob("test/**/*test.rb")
+ t.verbose = true
+end
+
+desc 'Builds the gem'
+task :build do
+ sh "gem build cassandra-queue.gemspec"
+end
+
+desc 'Builds and installs the gem'
+task :install => :build do
+ sh "gem install cassandra-queue-#{CassandraQueue::VERSION}"
+end
@@ -0,0 +1 @@
+WRITE ME
@@ -0,0 +1,34 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+
+require "cassandra-queue/version"
+
+Gem::Specification.new do |s|
+ s.name = "cassandra-queue"
+ s.version = CassandraQueue::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Jay Bhat"]
+ s.email = ["jbhat@ooyala.com"]
+ s.homepage = "http://www.ooyala.com"
+ s.summary = %q{Cassandra-backed general queue}
+ s.description = <<EOS
+Cassandra Queue is a queue that uses cassandra as a backend, that can hopefully be used
+as either a Job Queue, or a Message queue.
+EOS
+
+ s.rubyforge_project = "cassandra-queue"
+
+ ignores = File.readlines(".gitignore").grep(/\S+/).map {|pattern| pattern.chomp }
+ dotfiles = Dir[".*"]
+ s.files = Dir["**/*"].reject {|f| File.directory?(f) || ignores.any? {|i| File.fnmatch(i, f) } } + dotfiles
+ s.test_files = s.files.grep(/^test\//)
+
+ s.require_paths = ["lib"]
+
+ s.add_dependency "cassandra"
+
+ s.add_development_dependency "bundler", "~> 1.0.10"
+ s.add_development_dependency "scope", "~> 0.2.1"
+ s.add_development_dependency "mocha"
+ s.add_development_dependency "rake"
+end
@@ -0,0 +1,54 @@
+#!/usr/bin/env ruby
+# queue = CassandraQueue::Queue.get_queue("myqueue", "KeyspaceName", "localhost:9160")
+
+require "cassandra"
+include SimpleUUID
+
+module CassandraQueue
+ # Singleton class that manages our cassandra queues
+ class QueueManager
+ def self.queues
+ @queues ||= {}
+ end
+
+ def self.queue(qid, keyspace, servers)
+ key = :"#{qid}_#{keyspace}_#{servers.join(',')}"
+ queues[key] ||= Queue.new(qid, keyspace, servers)
+ end
+ end
+
+ class Queue
+ # Entry point for using a queue. Class method which will return you a queue object for that UUID
+ def self.get_queue(qid, keyspace = nil, servers = nil)
+ QueueManager.queue(qid, keyspace, servers)
+ end
+
+ def initialize(qid, keyspace, servers)
+ # Fail if called directly. We want queues to be managed by QueueManager
+ raise "Please create a managed queue using Queue::get_queue" unless caller[1] =~ /in `queue'/
+
+ @key = qid
+ # Set cassandra client if it has not already been set
+ @client ||= create_client(keyspace, servers)
+ end
+
+ def create_client(keyspace, servers)
+ ::Cassandra.new(keyspace, servers.flatten)
+ end
+
+ # Takes a message, throws it on the queue, and returns the message with a new part for the TimeUUID
+ def insert(payload, time=Time.now)
+
+ end
+
+ # Removes a TimeUUID, and it's message, from the queue
+ def delete(timeUUID)
+
+ end
+
+ # Show the current state of the queue, for things such as failure recovery
+ def list_queue
+
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module CassandraQueue
+ VERSION = "0.0.1"
+end

0 comments on commit d3e90fb

Please sign in to comment.