gpt4 book ai didi

redis - Rails 6 - sidekiq 不会在开发中出队

转载 作者:行者123 更新时间:2023-12-03 06:44:49 25 4
gpt4 key购买 nike

我在开发中遇到了这个问题: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.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的评论,希望我能在这里帮助我的结论:
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 都匹配!
我的开发配置在 初始化程序/cable.yml 被设置为开发:异步!所以我更新了它以匹配与以前相同的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com