调试 Resque::Server

Debugging Resque::Server

我们有两个 Rails 应用程序使用 Resque 和 Redis。 Resque 和 Redis 在两个应用程序上的配置相同,它们都使用 Rails 4.2 和 Resque 1.27.4.

然而,Resque 服务器在 /resque 路径的可用性在两个应用程序中最好描述为 "uneven"(我将把它们的真实姓名缩短为 "planning" 和 "staffing" 为了简化)。

resque_server_path /resque Resque::Server

我从哪里开始弄清楚哪里是对的,哪里是错的?

这是相关的 routes.rb 行(所有这些在两个应用程序中都是相同的):

mount Resque::Server, :at => '/resque', :constraints => RouteConstraint::Admin

lib/tasks/resque.rake:

require 'resque/tasks'

task "resque:setup" => :environment do
  ENV['QUEUE'] = '*'
  Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end

desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"

config/initializers/redis.rb:

# Cloned from staffing

uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/")
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

# Tell Resque which redis to use and ensure database connections don't go stale.
Resque.redis = REDIS
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }

# load job classes.
Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }

Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds

# https://github.com/resque/resque/wiki/Failure-Backends
require 'resque/failure/multiple'
require 'resque/failure/airbrake'
require 'resque/failure/redis'
Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Airbrake]
Resque::Failure.backend = Resque::Failure::Multiple

config.ru 在与 Resque 无关的设置中包含此行:

require 'resque/server'

接下来我应该看哪里?

ETA:我尝试​​通过安装 gem 切换到 resque-web,然后像这样更改 config/routes.rb

require "resque_web"

Rails.application.routes.draw do
  mount ResqueWeb::Engine, :at => "/resque", :constraints => RouteConstraint::SuperAdmin
end

(显然文件的内容远不止于此,但是 end 除外,它实际上是文件的顶部。)同样的问题仍然存在:访问 /resque 会引发错误 [=19= 】 尽管路线明明存在。这是 rake routes 输出的尾部:

Routes for ResqueWeb::Engine:
            overview GET    /overview(.:format)             resque_web/overview#show
       working_index GET    /working(.:format)              resque_web/working#index
         clear_queue PUT    /queues/:id/clear(.:format)     resque_web/queues#clear {:id=>/[^\/]+/}
              queues GET    /queues(.:format)               resque_web/queues#index
               queue GET    /queues/:id(.:format)           resque_web/queues#show {:id=>/[^\/]+/}
                     DELETE /queues/:id(.:format)           resque_web/queues#destroy {:id=>/[^\/]+/}
             workers GET    /workers(.:format)              resque_web/workers#index
              worker GET    /workers/:id(.:format)          resque_web/workers#show {:id=>/[^\/]+/}
       retry_failure PUT    /failures/:id/retry(.:format)   resque_web/failures#retry
  retry_all_failures PUT    /failures/retry_all(.:format)   resque_web/failures#retry_all
destroy_all_failures DELETE /failures/destroy_all(.:format) resque_web/failures#destroy_all
            failures GET    /failures(.:format)             resque_web/failures#index
             failure GET    /failures/:id(.:format)         resque_web/failures#show
                     DELETE /failures/:id(.:format)         resque_web/failures#destroy
               stats GET    /stats(.:format)                resque_web/stats#index
        stats_resque GET    /stats/resque(.:format)         resque_web/stats#resque
         stats_redis GET    /stats/redis(.:format)          resque_web/stats#redis
          stats_keys GET    /stats/keys(.:format)           resque_web/stats#keys
      keys_statistic GET    /stats/keys/:id(.:format)       resque_web/stats#keys {:id=>/[^\/]+/}
                root GET    /                               resque_web/overview#show

我想知道是否有关于发动机安装方式的信息?或者,如果有什么东西遮住了路线?

您应该调查 routes.rb 文件中定义的路由约束。当约束失败时,它们 return 404 Not Found 错误与您看到的错误一致。去掉约束会发生什么?