首页 > 解决方案 > Sidekiq 作业已入队,但未在 Heroku 上处理

问题描述

Rails 5.2 redis 4.0.1 sidekiq 5.1.3

Heroku 上的 RedisToGo

过程文件:

web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e production -C config/sidekiq.yml

sidekiq.yml

development:
  :concurrency: 5
production:
  :concurrency: 6
:queues:
  - default

配置/初始化/sidekiq.rb

if Rails.env.production?

  Sidekiq.configure_client do |config|
    config.redis = { url: ENV['REDISTOGO_URL'] || ENV['REDIS_URL'], size: 1 }
  end

  Sidekiq.configure_server do |config|
    pool_size = ENV['SIDEKIQ_DB_POOL'] || (Sidekiq.options[:concurrency] + 2)
    config.redis = { url: ENV['REDISTOGO_URL'] || ENV['REDIS_URL'], size: pool_size }

    Rails.application.config.after_initialize do
      Rails.logger.info("DB Connection Pool size for Sidekiq Server before disconnect is: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
      ActiveRecord::Base.connection_pool.disconnect!

      ActiveSupport.on_load(:active_record) do
        db_config = Rails.application.config.database_configuration[Rails.env]
        db_config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
        db_config['pool'] = pool_size
        ActiveRecord::Base.establish_connection(db_config)
        Rails.logger.info("DB Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
      end
    end
  end
end

在此处输入图像描述

我不知道为什么这项工作被卡在队列中。这项工作适用于我当地的开发。

任何帮助表示赞赏。

更新!根据这里的评论是heroku ps的输出:

=== web (Free): bundle exec puma -C config/puma.rb (1)
web.1: up 2018/06/15 18:49:56 +0700 (~ 5s ago)

=== worker (Free): bundle exec sidekiq -q default (1)
worker.1: crashed 2018/06/15 18:49:51 +0700 (~ 10s ago)

似乎一名工人因某种原因坠毁。

Heroku 日志:

2018-06-15T11:56:00.301716+00:00 app[web.1]: [4] Puma starting in cluster mode...
2018-06-15T11:56:00.301740+00:00 app[web.1]: [4] * Version 3.11.2 (ruby 2.4.1-p111), codename: Love Song
2018-06-15T11:56:00.301760+00:00 app[web.1]: [4] * Min threads: 5, max threads: 5
2018-06-15T11:56:00.301794+00:00 app[web.1]: [4] * Environment: production
2018-06-15T11:56:00.301801+00:00 app[web.1]: [4] * Process workers: 2
2018-06-15T11:56:00.301838+00:00 app[web.1]: [4] * Preloading application
2018-06-15T11:56:01.249511+00:00 app[worker.1]: DB Connection Pool size for Sidekiq Server before disconnect is: 5
2018-06-15T11:56:01.252654+00:00 app[worker.1]: could not connect to server: No such file or directory
2018-06-15T11:56:01.252657+00:00 app[worker.1]: Is the server running locally and accepting
2018-06-15T11:56:01.252659+00:00 app[worker.1]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

标签: ruby-on-railsherokuredissidekiq

解决方案


在与 Heroku 的技术支持人员交谈后,我发现我需要改变我的 db yaml 文件编码方式。

我将其更改为以下内容:

production:
  url: <%= ENV['DATABASE_URL'] %>

这似乎可以解决问题。


推荐阅读