作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在开发中遇到了这个问题:Sidekiq 将工作排入队列,但从不出队。在生产(Heroku)上,一切正常。这是我终端上启动消息的一小部分:
2020-06-16T17:39:20.481Z pid=7317 tid=oxx33ap5d INFO: Booted Rails 6.0.2.1 application in development environment
2020-06-16T17:39:20.481Z pid=7317 tid=oxx33ap5d INFO: Running in ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin16]
2020-06-16T17:39:20.481Z pid=7317 tid=oxx33ap5d INFO: See LICENSE and the LGPL-3.0 for licensing details.
2020-06-16T17:39:20.482Z pid=7317 tid=oxx33ap5d INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2020-06-16T17:39:20.482Z pid=7317 tid=oxx33ap5d INFO: Booting Sidekiq 6.0.6 with redis options {:id=>"Sidekiq-server-PID-7317", :url=>nil}
2020-06-16T17:39:20.536Z pid=7317 tid=oxx33ap5d DEBUG: Client Middleware:
2020-06-16T17:39:20.536Z pid=7317 tid=oxx33ap5d DEBUG: Server Middleware: Sidekiq::Failures::Middleware
2020-06-16T17:39:20.536Z pid=7317 tid=oxx33ap5d INFO: Starting processing, hit Ctrl-C to stop
2020-06-16T17:39:20.536Z pid=7317 tid=oxx33ap5d DEBUG: {:queues=>["default", "mailers"], :labels=>[], :concurrency=>3, :require=>".", :environment=>nil, :timeout=>240, :poll_interval_average=>nil, :average_scheduled_poll_interval=>5, :error_handlers=>[#<Sidekiq::ExceptionHandler::Logger:0x00007ffe1b158260>], :death_handlers=>[], :lifecycle_events=>{:startup=>[], :quiet=>[], :shutdown=>[], :heartbeat=>[]}, :dead_max_jobs=>10000, :dead_timeout_in_seconds=>15552000, :reloader=>#<Sidekiq::Rails::Reloader @app=Wadzatsong::Application>, :verbose=>true, :config_file=>"./config/sidekiq.yml", :strict=>true, :tag=>"wadzatsong", :identity=>"MBP-de-apple:7317:18f040a5293c"}
2020-06-16T17:39:20.586Z pid=7317 tid=oxx3b6ag9 class=PlaylistJob jid=9fda5f6075587921f5d3be51 INFO: start
2020-06-16T17:39:20.586Z pid=7317 tid=oxx3b6aid class=PlaylistJob jid=d1b5536379c0a65ec73381f6 INFO: start
2020-06-16T17:39:20.586Z pid=7317 tid=oxx3b6ac1 class=PlaylistJob jid=122c610b9d44942d06652289 INFO: start
2020-06-16T17:39:27.001Z pid=7317 tid=oxx3b6ac1 class=PlaylistJob jid=122c610b9d44942d06652289 elapsed=6.415 INFO: fail
2020-06-16T17:39:27.001Z pid=7317 tid=oxx3b6ac1 WARN: {"context":"Job raised exception","job":{"retry":true,"queue":"default","class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"PlaylistJob","args":[{"job_class":"PlaylistJob","job_id":"aa761c60-ead2-44a6-b5ab-41559a595143","provider_job_id":null,"queue_name":"default","priority":null,"arguments":["French"],"executions":0,"exception_executions":{},"locale":"en","timezone":"UTC","enqueued_at":"2020-06-15T17:31:35Z"}],"jid":"122c610b9d44942d06652289","created_at":1592242295.783063,"enqueued_at":1592242295.783238,"error_message":"429 Too Many Requests","error_class":"RestClient::TooManyRequests","processor":"MBP-de-apple:7317","failed_at":1592329166.999786},"jobstr":"{\"retry\":true,\"queue\":\"default\",\"class\":\"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper\",\"wrapped\":\"PlaylistJob\",\"args\":[{\"job_class\":\"PlaylistJob\",\"job_id\":\"aa761c60-ead2-44a6-b5ab-41559a595143\",\"provider_job_id\":null,\"queue_name\":\"default\",\"priority\":null,\"arguments\":[\"French\"],\"executions\":0,\"exception_executions\":{},\"locale\":\"en\",\"timezone\":\"UTC\",\"enqueued_at\":\"2020-06-15T17:31:35Z\"}],\"jid\":\"122c610b9d44942d06652289\",\"created_at\":1592242295.783063,\"enqueued_at\":1592242295.783238}"}
2020-06-16T17:39:27.002Z pid=7317 tid=oxx3b6ac1 WARN: RestClient::TooManyRequests: 429 Too Many Requests
2020-06-16T17:39:27.002Z pid=7317 tid=oxx3b6ac1 WARN: /Users/pierre/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:223:in `exception_with_response'
/Users/pierre/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:103:in `return!'
/Users/pierre/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rest-client-2.0.2/lib/restclient/request.rb:809:in `process_result'
/Users/pierre/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rest-client-2.0.2/lib/restclient/request.rb:725:in `block in transmit'
/Users/pierre/.rbenv/versions/2.6.5/lib/ruby/2.6.0/net/http.rb:920:in `start'
所有设置似乎都是正确的,因为它在 heroku 上运行良好:
config/application.rb
[...]
config.active_job.queue_adapter = :sidekiq
sidekiq.yml
:concurrency: 3
:timeout: 240
:verbose: true
:queues: # Queue priority: https://github.com/mperham/sidekiq/wiki/Advanced-Options
- default
- mailers
路线.rb
Rails.application.routes.draw do
# Sidekiq Web UI, only for admins.
require "sidekiq/web"
authenticate :user, lambda { |u| u.admin } do
mount Sidekiq::Web => '/sidekiq'
end
end
我的工作 :
class PlaylistJob < ApplicationJob
queue_as :default
def perform(name)
[...]
end
end
我的 http://localhost:3000/sidekiq 显示以下内容。我手动失败了 204,但是 11 次重试从未成功
215 Processed
204 Failed
0 Busy
0 Enqueued
11 Retries
0 Scheduled
0 Dead
用于 Redis 的 Sidekiq 设置在这里
$redis = Redis.new
url = ENV["REDISCLOUD_URL"]
if url
Sidekiq.configure_server do |config|
config.redis = { url: url }
end
Sidekiq.configure_client do |config|
config.redis = { url: url }
end
$redis = Redis.new(:url => url)
end
最佳答案
所以我发现并修复了它,感谢cmramseyer的评论,希望我能在这里帮助我的结论:
Sidekiq for Redis 的设置在这里
初始化器/redis.rb :
$redis = Redis.new
url = ENV["REDISCLOUD_URL"]
if url
Sidekiq.configure_server do |config|
config.redis = { url: url }
end
Sidekiq.configure_client do |config|
config.redis = { url: url }
end
$redis = Redis.new(:url => url)
end
如 cmramseyer 所示,我将本地 url 更改为
url = "redis://localhost:6379/0"
实际上,生产环境中已经使用的 url channel 是 redis://localhost:6379/1,所以我更新了这个 url 以匹配
"redis://localhost:6379/1"
. 0 或 1,重要的是所有 URL 都匹配!
development:
adapter: redis
url: <%= ENV.fetch("REDISCLOUD_URL") { "redis://localhost:6379/1" } %>
channel_prefix: _wadzatsong_development
test:
adapter: test
production:
adapter: redis
url: <%= ENV.fetch("REDISCLOUD_URL") { "redis://localhost:6379/1" } %>
channel_prefix: _wadzatsong_production
这就是所有的人!
关于redis - Rails 6 - sidekiq 不会在开发中出队,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62415369/
我的 JavaScript 代码中有一道数学题。我需要将给定数量的玩家随机分成 2 队,这样每次 - 如果玩家想再次比赛 - 团队都会重新组成,并且在形成所有组合之前他们应该不同。 假设我有 4 个玩
我是一名优秀的程序员,十分优秀!