Ruby on Rails: 操作现在正在进行中 - 连接(2) 将被阻塞

6
我正在处理一个别人做的网站,它有个生产版本。
我试图向那些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 操作正在进行中 - 连接(2)将被阻止 但是没有任何数据发送。
我不确定如何解决这个问题。
编辑: 我可以看到在生产网站上我可以访问路由/ sidekiq。 路由文件有这个块:
  authenticate :user, lambda { |u| u.admin? } do
    mount Sidekiq::Web => '/sidekiq'
  end

我可以查看Web界面并查看所有作业。 那里一切正常。 但是我需要访问运行在localhost:3000上的开发版本。

尝试本地访问仍然会导致:

操作正在进行中- connect(2)将被阻止

  #  # 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

2个回答

21

生产服务器正在运行Ubuntu,并已安装redis-server

我在本地未安装此软件。(我是通过Windows WSL使用Ubuntu)

sudo apt install redis-server

我现在可以访问Web界面。


6
我曾经处于完全相同的情况下,问题就在这里!我在我的WSL环境中安装并启动了redis-server服务,然后它就工作了。谢谢! - Sergio Gonzalez

0

确保 Redis 已启动:

 sudo service redis-server restart

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接