Permalink
Browse files

Makes possible starting the worker as a daemon

  • Loading branch information...
1 parent 38bab5f commit 12f044cc0459c4e84d2191a2b904b6292feac1a8 @guiocavalcanti guiocavalcanti committed Oct 31, 2012
Showing with 40 additions and 3 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 Gemfile
  3. +2 −0 Gemfile.lock
  4. +6 −0 README.mkd
  5. +15 −0 permitd.rb
  6. +14 −3 worker.rb
View
@@ -2,3 +2,5 @@
*.swo
bin
.bundle
+tmp
+log
View
@@ -10,6 +10,7 @@ gem 'amqp'
gem 'yajl-ruby'
gem 'rake'
gem 'configurable'
+gem 'daemons'
group :development, :test do
gem 'rspec'
View
@@ -33,6 +33,7 @@ GEM
configurable (1.0.0)
config_parser (~> 0.5.4)
lazydoc (~> 1.0)
+ daemons (1.1.9)
debugger (1.2.0)
columnize (>= 0.3.1)
debugger-linecache (~> 1.1.1)
@@ -98,6 +99,7 @@ DEPENDENCIES
amqp
bson_ext
configurable
+ daemons
debugger
em-mongo
em-synchrony
View
@@ -99,8 +99,14 @@ permit > curl -H 'Accept: application/json' http://0.0.0.0:9000/rules?resource_i
## Running
+### Server
+
You just need to run the server with ``ruby server.rb -sv``
+### AMQP Consumer
+
+``bundle exec ruby worker.rb`` or, as a daemon, ``bundle exec permitd.rb start``
+
### Deploy
In order to deploy on heroku you should enable some MongoDB addon and set environment variables:
View
@@ -0,0 +1,15 @@
+require 'bundler/setup'
+require 'daemons'
+
+require_relative 'boot'
+
+options = {
+ :backtrace => true,
+ :log_output => true,
+ :app_name => 'permit',
+ :dir_mode => :script,
+ :dir => '/tmp/pids',
+ :log_dir => "#{File.expand_path File.dirname __FILE__}/log"
+}
+
+Daemons.run("worker.rb", options)
View
@@ -1,18 +1,29 @@
-require_relative 'boot'
+$:.unshift File.expand_path 'lib'
+
require 'amqp'
require 'yajl/json_gem'
-AMQP.start do |connection|
+require 'permit/config'
+require 'permit/consumer'
+require 'permit/worker'
+AMQP.start do |connection|
EventMachine.synchrony do
- Goliath.env = :development
+ Permit.configure do |c|
+ dirname = "#{File.dirname(__FILE__)}/log"
+ Dir.mkdir dirname unless File.exists?(dirname)
+ c.logger = Logger.new("#{dirname}/permitd_#{c.env}.log")
+ end
+
channel = AMQP::Channel.new(connection)
exchange = channel.topic("permit", :auto_delete => true)
consumer = Permit::Consumer.new
worker = Permit::Worker.new(:consumer => consumer, :channel => channel,
:exchange => exchange)
worker.start
+ # For testing...
+ #
# EM::add_periodic_timer do
# policy = {:resource_id => 'r', :subject_id => 's',
# :actions => { :read => true } }

0 comments on commit 12f044c

Please sign in to comment.