Ruby on Rails:操作正在进行中 - connect(2) 会阻塞
Ruby on Rails: Operation now in progress - connect(2) would block
我在别人制作的网站上工作。有生产版。
我正在尝试向其属性在 30 天内未更新的用户发送电子邮件。
一切正常,直到我尝试使用 deliver_later
。我使用 deliver_later
的原因是 deliver_now
导致每秒发送过多电子邮件的问题。我目前正在使用 Mailtrap 进行测试,但我想我会 运行 在生产中解决这类问题。
所以我选择每封邮件等待 1 秒:
@testproperties = Property.has_not_updated.includes(:user)
@testproperties.each do |property|
UserMailer.with(property: property, user: property.user).check_listing.deliver_later(wait:1.seconds)
end
这导致 IO::EINPROGRESSWaitWritable
Operation now in progress - connect(2) would block
没有任何发送。
我不知道如何解决这个问题。
编辑:
我在生产现场看到可以访问路由/sidekiq。路由文件有这个块:
authenticate :user, lambda { |u| u.admin? } do
mount Sidekiq::Web => '/sidekiq'
end
我可以查看 Web 界面并查看所有作业。一切都在那里工作。但我需要在 localhost:3000
.
上访问开发版本 运行ning
尝试在本地访问它仍然会导致:
Operation now in progress - connect(2) would block
# # Socket#connect
def connect_nonblock(addr, exception: true)
__connect_nonblock(addr, exception)
end
end
Sidekiq.rb:
require 'sidekiq'
unless Rails.env.test?
host = 'localhost'
port = '6379'
namespace = 'sitename'
Sidekiq.configure_server do |config|
config.redis = { url: "redis://#{host}:#{port}", namespace: namespace }
schedule_file = "config/schedule.yml"
if File.exists?(schedule_file)
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
end
config.server_middleware do |chain|
chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes
end
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware, expiration: 30.minutes
end
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://#{host}:#{port}", namespace: namespace }
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware, expiration: 30.minutes
end
end
end
对于 cable.yml:
development:
adapter: async
url: redis://localhost:6379/1
channel_prefix: sitename_dev
test:
adapter: async
production:
adapter: redis
url: redis://localhost:6379/1
channel_prefix: sitename_production
生产服务器是 运行 Ubuntu 并且他们已经安装了 redis-server
。
我没有在本地安装它。 (我正在使用 Ubuntu 到 Windows WSL)
sudo apt install redis-server
我现在可以访问网络界面了。
我在别人制作的网站上工作。有生产版。
我正在尝试向其属性在 30 天内未更新的用户发送电子邮件。
一切正常,直到我尝试使用 deliver_later
。我使用 deliver_later
的原因是 deliver_now
导致每秒发送过多电子邮件的问题。我目前正在使用 Mailtrap 进行测试,但我想我会 运行 在生产中解决这类问题。
所以我选择每封邮件等待 1 秒:
@testproperties = Property.has_not_updated.includes(:user)
@testproperties.each do |property|
UserMailer.with(property: property, user: property.user).check_listing.deliver_later(wait:1.seconds)
end
这导致 IO::EINPROGRESSWaitWritable
Operation now in progress - connect(2) would block
没有任何发送。
我不知道如何解决这个问题。
编辑: 我在生产现场看到可以访问路由/sidekiq。路由文件有这个块:
authenticate :user, lambda { |u| u.admin? } do
mount Sidekiq::Web => '/sidekiq'
end
我可以查看 Web 界面并查看所有作业。一切都在那里工作。但我需要在 localhost:3000
.
尝试在本地访问它仍然会导致:
Operation now in progress - connect(2) would block
# # Socket#connect
def connect_nonblock(addr, exception: true)
__connect_nonblock(addr, exception)
end
end
Sidekiq.rb:
require 'sidekiq'
unless Rails.env.test?
host = 'localhost'
port = '6379'
namespace = 'sitename'
Sidekiq.configure_server do |config|
config.redis = { url: "redis://#{host}:#{port}", namespace: namespace }
schedule_file = "config/schedule.yml"
if File.exists?(schedule_file)
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
end
config.server_middleware do |chain|
chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes
end
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware, expiration: 30.minutes
end
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://#{host}:#{port}", namespace: namespace }
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware, expiration: 30.minutes
end
end
end
对于 cable.yml:
development:
adapter: async
url: redis://localhost:6379/1
channel_prefix: sitename_dev
test:
adapter: async
production:
adapter: redis
url: redis://localhost:6379/1
channel_prefix: sitename_production
生产服务器是 运行 Ubuntu 并且他们已经安装了 redis-server
。
我没有在本地安装它。 (我正在使用 Ubuntu 到 Windows WSL)
sudo apt install redis-server
我现在可以访问网络界面了。