Commit 923eb89c1de137e8daeb871e63530070aa70379e

Authored by Dmitriy Zaporozhets
2 parents ad3eefdc 6ddbee5d

Merge pull request #1528 from tsigo/resque_init

Consolidate Resque-related initializers
config/initializers/4_resque.rb 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +# Custom Redis configuration
  2 +rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
  3 +rails_env = ENV['RAILS_ENV'] || 'development'
  4 +config_file = File.join(rails_root, 'config', 'resque.yml')
  5 +
  6 +if File.exists?(config_file)
  7 + resque_config = YAML.load_file(config_file)
  8 + Resque.redis = resque_config[rails_env]
  9 +end
  10 +
  11 +# Queues
  12 +Resque.watch_queue(PostReceive.instance_variable_get("@queue"))
  13 +
  14 +# Authentication
  15 +require 'resque/server'
  16 +class Authentication
  17 + def initialize(app)
  18 + @app = app
  19 + end
  20 +
  21 + def call(env)
  22 + account = env['warden'].authenticate!(:database_authenticatable, :rememberable, scope: :user)
  23 + raise "Access denied" if !account.admin?
  24 + @app.call(env)
  25 + end
  26 +end
  27 +
  28 +Resque::Server.use Authentication
  29 +
  30 +# Mailer
  31 +Resque::Mailer.excluded_environments = []
config/initializers/4_resque_queues.rb
@@ -1 +0,0 @@ @@ -1 +0,0 @@
1 -Resque.watch_queue(PostReceive.instance_variable_get("@queue"))  
config/initializers/resque.rb
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'  
2 -rails_env = ENV['RAILS_ENV'] || 'development'  
3 -config_file = File.join(rails_root, 'config', 'resque.yml')  
4 -  
5 -if File.exists?(config_file)  
6 - resque_config = YAML.load_file(config_file)  
7 - Resque.redis = resque_config[rails_env]  
8 -end  
config/initializers/resque_authentication.rb
@@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
1 -require 'resque/server'  
2 -class Authentication  
3 - def initialize(app)  
4 - @app = app  
5 - end  
6 -  
7 - def call(env)  
8 - account = env['warden'].authenticate!(:database_authenticatable, :rememberable, scope: :user)  
9 - raise "Access denied" if !account.admin?  
10 - @app.call(env)  
11 - end  
12 -end  
13 -  
14 -Resque::Server.use Authentication  
15 \ No newline at end of file 0 \ No newline at end of file
config/initializers/resque_mailer.rb
@@ -1 +0,0 @@ @@ -1 +0,0 @@
1 -Resque::Mailer.excluded_environments = []