我使用sidekiq gem来处理后台作业,使用sidekiq-cron来调度特定时间间隔的作业。
在config/routes.rb中,我添加了以下内容,以便为sidekiq UI端点提供身份验证。
authentication = ->req { req.env["warden"].authenticate!}
constraints authentication do
mount Sidekiq::Web => '/sidekiq'
end当我点击立即入队按钮(参考附图),它抛出以下错误和作业未添加到队列。它在没有身份验证的情况下工作。
ActionController::RoutingError (No route matches [GET] "/sidekiq/cron/my_report/enque"):
F, [2019-04-11T11:00:27.684536 #9365] FATAL -- :
F, [2019-04-11T11:00:27.684733 #9365] FATAL -- : actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
railties (5.2.3) lib/rails/engine.rb:524:in `call'
puma (3.12.1) lib/puma/configuration.rb:227:in `call'
puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
puma (3.12.1) lib/puma/server.rb:474:in `process_client'
puma (3.12.1) lib/puma/server.rb:334:in `block in run'
puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'

发布于 2019-04-11 20:24:25
我用的是Sidekiq Pro和cron gem。也许我的配置可以帮助您(尽管我使用基本的HTTP auth表单)。
在application.rb中
require 'sidekiq-pro'
require 'sidekiq/pro/web'
require 'sidekiq/cron/web'
class Application < Rails::Application
Sidekiq::Web.use Rack::Auth::Basic do |username, password|
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(Rails.application.secrets.sidekiq_username)) &
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(Rails.application.secrets.sidekiq_password))
end if Rails.env.production?
end然后,在routes.rb上,我只有以下内容:
mount Sidekiq::Web => '/sidekiq'因此,每次我转到某个-url/sidekiq时,都会出现一个auth表单。
希望这能对你有所帮助。
https://stackoverflow.com/questions/55625382
复制相似问题