Heroku 上的 Sidekiq 任务已经加入队列但没有被处理

4
Rails 5.2 redis 4.0.1 sidekiq 5.1.3
Heroku上的RedisToGo
Proc文件:
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

config/initialize/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

enter image description here

我不知道为什么作业被卡在队列中。该作业在我的本地开发环境中可以正常工作。
感谢任何帮助。
更新!根据这里的评论,以下是 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"?

1
你可以运行 heroku ps 命令来检查工作进程吗?也许这篇文章会有所帮助:https://dev59.com/w2Yr5IYBdhLWcg3wVYog - Artem Dorodovskyi
看起来 Sidekiq 可以读取你的 Redis 数据库,因为它有一个作业在排队。确保你至少有 1 个 dyno 工作者。另外,重新启动服务器。 - hcarreras
重新启动服务器,但工作进程再次崩溃。 - chell
在您的项目目录中执行 heroku restart - Artem Dorodovskyi
将您的数据库设置中的池大小增加到25或50。 - Artem Dorodovskyi
heroku addons:create heroku-postgresql 将 Postgres 添加到您的 Heroku。 - Artem Dorodovskyi
2个回答

1
在与Heroku技术支持交谈后,我发现需要更改我的db yaml文件的编码方式。
我将其更改为以下内容:
production:
  url: <%= ENV['DATABASE_URL'] %>

那似乎解决了这个问题。


-1

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