Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Upgrade to latest bundler

Provide sample dispatch logic
Fix right_aws issues under Ruby 1.9
  • Loading branch information...
commit 2940dbcf5aa1c0a43a5febd11e4987e5cd12406b 1 parent f6fa8b6
@mperham authored
View
11 qanat/Gemfile
@@ -5,7 +5,12 @@ gem 'daemon-kit', '>= 0.1.7.12'
gem 'em-http-request', '>= 0.2.6'
gem 'mime-types', '>= 1.16'
gem 'activerecord', '= 2.3.5'
-gem 'pg', '>= 0.8.0'
+gem 'postgres-pr', '>= 0.6.0'
+gem 'eventmachine', '>= 0.10.12'
+gem 'em_postgresql', '>= 0.1.1'
-gem "rspec", :only => :testing
-gem "mocha", :only => :testing
+group :test do
+ gem "rspec"
+ gem "mocha"
+ gem 'right_aws', :git => "git://github.com/mperham/right_aws.git"
+end
View
11 qanat/config/boot.rb
@@ -3,9 +3,14 @@
DAEMON_ROOT = "#{File.expand_path(File.dirname(__FILE__))}/.." unless defined?( DAEMON_ROOT )
-# Use bundler if available
-if File.exists?( File.join( DAEMON_ROOT, 'vendor', 'gems', 'environment.rb' ) )
- require File.join( DAEMON_ROOT, 'vendor', 'gems', 'environment' )
+begin
+ require File.expand_path('../../.bundle/environment', __FILE__)
+rescue LoadError
+ puts "Please install bundler:"
+ puts " gem install bundler -v '~>0.9.3'"
+ puts "and then initialize Qanat's gem environment:"
+ puts " bundle install && bundle lock"
+ exit
end
module DaemonKit
View
1  qanat/config/environment.rb
@@ -4,7 +4,6 @@
#ENV['DAEMON_ENV'] ||= 'production'
# Boot up
-require File.join(File.dirname(__FILE__), '../vendor/gems/environment')
require File.join(File.dirname(__FILE__), 'boot')
DaemonKit::Initializer.run do |config|
View
51 qanat/lib/dispatch.rb
@@ -0,0 +1,51 @@
+require 'yaml'
+require 'erb'
+require 'active_record'
+
+RAILS_ENV=DaemonKit.configuration.environment
+
+ActiveRecord::Base.configurations = YAML::load(ERB.new(File.read(File.join(DAEMON_ROOT, 'config', 'database.yml'))).result)
+ActiveRecord::Base.default_timezone = :utc
+ActiveRecord::Base.logger = DaemonKit.logger
+ActiveRecord::Base.logger.level = Logger::INFO
+ActiveRecord::Base.time_zone_aware_attributes = true
+Time.zone = 'UTC'
+ActiveRecord::Base.establish_connection
+
+# Your custom message dispatch logic goes below. This is
+# a sample of how to do it but you can modify as necessary.
+#
+# Our message processing classes go in lib/processors.
+#
+# Example message:
+# { :msg_type => 'index_page', :page_id => 15412323 }
+#
+# Qanat will execute:
+# processor = IndexPage.new
+# processor.process(hash)
+# to handle the message.
+
+$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'processors')))
+# require 'your_message_processor1'
+# require 'your_message_processor2'
+
+module Qanat
+
+ def self.dispatch(msg)
+ hash = YAML::load(msg)
+ name = hash.fetch(:msg_type).to_s.camelize
+ profile(hash) do
+ name.constantize.new.process(hash)
+ end
+ end
+
+ def self.profile(hash)
+ a = Time.now
+ return yield
+ ensure
+ DaemonKit.logger.info("Processed message: #{hash.inspect} in #{Time.now - a} sec")
+ end
+
+end
+
+
View
2  qanat/libexec/qanat-daemon.rb
@@ -12,8 +12,6 @@
end
end
-$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'processors')))
-
require 'dispatch'
Qanat.run do
View
1  qanat/tasks/testing.rake
@@ -1,6 +1,7 @@
require 'right_aws'
require 'qanat'
+# Some sample Rake tasks to perform common queue tasks.
namespace :msg do
task :push do
hash = Qanat.load('amzn')

1 comment on commit 2940dbc

Please sign in to comment.
Something went wrong with that request. Please try again.