【问题标题】:Rails 5.2 and Sidekiq 5: Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for "localhost" port 25Rails 5.2 和 Sidekiq 5:Errno::EADDRNOTAVAIL:无法分配请求的地址 - “localhost”端口 25 的连接(2)
【发布时间】:2019-05-20 11:56:56
【问题描述】:

我正在尝试使用 Sidekiq 和 deliver_later 发送电子邮件。

在我的config/sidekiq.yml 我有:

:verbose: true
:concurrency: 25
:queues:
  - [mailers, 7]
  - [critical, 6]
  - [default, 5]
  - [low, 4]

在我的工人中,我尝试这样做: Buyer::OffersMailer.instant_for_published_offer(info_to_deliver).deliver_later

我在 Sidekiq 管理面板中看到我的邮件工作卡在“重试”中并出现此错误:

Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for "localhost" port 25

我的应用程序可以发送 deliver_now 电子邮件,我认为这拒绝了 SMPTP 可能有问题的假设。任何想法,可能有什么问题?

更新 此外,电子邮件不会在生产中传递,我的配置如下所示:

config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { host: "https://myapp.com" }
config.action_mailer.asset_host = "https://myapp.com"
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address        => 'myval',
  :port           => '587',
  :authentication => :plain,
  :user_name      => 'myval',
  :password       => Rails.application.credentials.mailgun_smtp_pass,
  :enable_starttls_auto => true
}

【问题讨论】:

  • 您的config.action_mailer 可能配置错误。它似乎试图通过STMP(端口25)向localhost发送邮件。
  • @PavelMikhailyuk 看起来像,但是 deliver_now 工作正常。此外,它不适用于我的 SMPTP 设置的生产环境 - 请参阅上面的更新。
  • deliver_nowRails 进程中发送电子邮件,而 deliver_laterSidekiq 进程中执行此操作。因此,您很可能为 Sidekiq 配置了错误的 环境。在 Rails 和 Sidekiq 进程中测试Rails.env。它们应该是相同的。
  • @PavelMikhailyuk 看起来你是对的。当我在我的生产控制台bundle exec sidekiq -e production 中这样做时,它确实有效。现在最大的问题是,为什么我的带有main_worker: bundle exec sidekiq -e production 的 Procfile 不起作用?
  • 这是另一个问题,这取决于您的产品是如何配置的。

标签: ruby-on-rails actionmailer sidekiq ruby-on-rails-5.2


【解决方案1】:

由于您的电子邮件使用#deliver_now 方法正确发送,这意味着您的Mailer 配置很好。现在除此之外,您应该在 application.rb 配置文件中包含它:

config.active_job.queue_adapter = :sidekiq

config\initializers\sidekiq.rb 中,您需要配置 Redis URL:

Sidekiq.configure_server do |config|
  config.redis = { url: (ENV["REDIS_URL"] || 'redis://localhost:6379/0') }
end

Sidekiq.configure_client do |config|
  config.redis = { url: (ENV["REDIS_URL"] || 'redis://localhost:6379/0') }
end

【讨论】:

    【解决方案2】:

    生产中的错误是由于 Procfile 中的环境设置造成的。截至Sidekiq docs 在我的情况下工作RAILS_ENV=production

    所以我的工作过程文件看起来像这样:

    main_worker: bundle exec sidekiq RAILS_ENV=production
    

    如果您使用 HerokuDokku,请不要忘记扩展您的工作线程。

    【讨论】:

      猜你喜欢
      • 2012-11-30
      • 2019-08-27
      • 1970-01-01
      • 2020-01-24
      • 2016-07-16
      • 2011-10-13
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      相关资源
      最近更新 更多