Commit 6ddbee5d89b3ea0e5d2a8f2b72416dcb7ab39fe5

Authored by Robert Speicher
1 parent 2cd0caaf

Consolidate all Resque-related initializers into "4_resque"

config/initializers/4_resque.rb
  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
1 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/resque.rb
... ... @@ -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   -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 0 \ No newline at end of file
config/initializers/resque_mailer.rb
... ... @@ -1 +0,0 @@
1   -Resque::Mailer.excluded_environments = []