0

I'm using resque for background processing, the route /resque works fine in development, but in production (using passenger) it doesn't, the log/production.log shows the error:

ActionController::RoutingError (No route matches [GET] "/resque/overview")

when I run the command

rails routes | grep resque

it shows:

/resque                                                                        
      #<Resque::Server app_file="/var/www/webroot/ROOT/vendor/bundle/ruby/2.7.0/gems/resque-2.0.0/lib/resque/server.rb">

my Gemfile:

gem 'resque'

my config/initializers/resque.rb

require 'resque/server' # this is needed for resque web UI

redis_url = {
  development: 'localhost:6379',
  production: Redis.new(url: 'redis://{user}:{password}/{host_url}:6379/0')
}
rails_env = Rails.env.to_sym || 'development'

Resque.redis = redis_url[rails_env.to_sym]

my routes

authenticated :user, -> user { user.admin? }  do
    mount Resque::Server.new, :at => "/resque"
 end
medBouzid
  • 7,484
  • 10
  • 56
  • 86

1 Answers1

0

I will answer my question,

The issue was the following line

authenticated :user, -> user { user.admin? }  do

Which seems to not work with my installed devise version 4.7.3

Once I get rid of it, the /resque route started to work! but I needed a way to restrict viewing that route for admin users only, so here is what I did,

in the config/initializers/resque.rb I added this:

require 'resque/server' # this is needed for resque web UI

class SecureResqueServer < Resque::Server
  before do
    redirect '/' unless request.env['warden'].user&.admin?
  end
end

Then in routes.rb my /resque route becomes:

mount SecureResqueServer.new, :at => "/resque"

The above class and route are from Resque, Devise and admin authentication

That solved my issue... not sure but it seems that this issue is related to this:

https://github.com/heartcombo/devise/issues/5019

medBouzid
  • 7,484
  • 10
  • 56
  • 86