简体   繁体   English

docker + rails + redis - 救援人员没有运行

[英]docker + rails + redis - rescue workers are not running

I've created a docker environment that creates 3 images: rails, postgresql and redis. 我创建了一个可以创建3个图像的docker环境:rails,postgresql和redis。 It has been working quite well but I have found that my redis image does not seem to have any workers running. 它一直运作良好,但我发现我的redis图像似乎没有任何工人运行。

Docker Info Docker信息

My docker-compose.yml is as follows 我的docker-compose.yml如下

web:  
  build: .
  command: bundle exec unicorn -p 3000 -c config/unicorn.rb
  volumes:
    - .:/fitmo
    - ../fitmo-core:/fitmo-core
  ports:
    - "3000:3000"
  links:
    - db
    - redis
  environment:
    - REDIS_URL=redis://redis:6379

db:
  build: ./db/docker-files
  ports:
    - "5432"

redis:  
  image: redis:2.8
  ports:
    - "6379"

Resque Config Resque配置

require 'resque'
require 'resque-scheduler'
require 'resque_scheduler/server'
require 'appsignal/integrations/resque'
require 'yaml'

if Rails.env.test?
  require 'mock_redis'
  $redis = MockRedis.new
else
  uri = URI.parse(ENV['REDIS_URL'])
  $redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)
end

Resque.redis = $redis
Resque.schedule = YAML.load_file(File.join(Rails.root, 'config/resque_schedule.yml'))

Resque.before_fork do
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

Resque.after_fork do
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

module Resque

  def queued_jobs
    queues = Hash.new
    Resque.queues.each do |queue|
      jobs = []
      Resque.peek(queue, 0, 5000).each do |job|
        jobs.push({klass: job['class'], args: job['args']})
      end
      queues[queue] = jobs
    end
    queues
  end

  def queued?(klass, *args)
    queued_jobs.select do |job|
      job[:klass] == klass.to_s && job[:args] == args
    end.any?
  end

  def enqueue_once(klass, *args)
    enqueue(klass, *args) unless queued?(klass, *args)
  end

end

Ruby Gems Ruby Gems

The following are the relevant gems being used. 以下是使用的相关宝石。 The commented out versions are the latest versions of the gems but I don't think this is an issue as the current versions are working fine in Heroku environments. 注释掉的版本是宝石的最新版本,但我不认为这是一个问题,因为当前版本在Heroku环境中运行良好。 I've also include rescue mailer and scheduler for thoroughness. 我还包括救援邮件和调度程序的彻底性。 They are not in play for the question 他们没有参与这个问题

gem 'redis',            '3.0.7'         #'~> 3.2.0'
gem 'resque',           '~> 1.25.2'     #'~> 1.25.2'
gem 'resque_mailer',    '~> 1.0.1'      #'~> 2.2.7'
gem 'resque-scheduler', '~> 2.5.5'      #'~> 4.0.0'

Testing Info 测试信息

I have confirmed that redis is accessible from the web container by telnetting to host redis on port 6379. I've also output the value of Rescue.info which shows that there are items queued but now workers running 我已经确认可以通过telnet到端口6379上的主机redis从Web容器访问redis。我还输出Rescue.info的值,该值显示有项目已排队但现在正在运行的工作程序

resque info: {:pending=>1, :processed=>0, :queues=>2, :workers=>0, :working=>0, :failed=>0, :servers=>["redis://redis:6379/0"], :environment=>"development"}

I'm stuck at this point as I'm not sure how to get the workers running. 我坚持这一点,因为我不确定如何让工人跑步。 Any suggestions? 有什么建议?

I was able to solve this by including a new image to be started based on the web image. 我能够通过包含基于Web图像启动的新图像来解决这个问题。 My new docker-compose.yml file is as follows (added new worker image): 我的新docker-compose.yml文件如下(添加了新的worker图像):

web:  
  build: .
  command: bundle exec unicorn -p 3000 -c config/unicorn.rb
  volumes:
    - .:/fitmo
    - ../fitmo-core:/fitmo-core
  ports:
    - "3000:3000"
  links:
    - db
    - redis
  environment:
    - REDIS_URL=redis://redis:6379

worker:
  build: .
  command: bundle exec rake environment resque:work QUEUE=*
  volumes:
    - .:/fitmo
    - ../fitmo-core:/fitmo-core
  links:
    - db
    - redis
  environment:
    - REDIS_URL=redis://redis:6379

db:
  build: ./db/docker-files
  ports:
    - "5432"

redis:  
  image: redis:latest
  ports:
    - "6379"

There is a subsequent issue if you have AppSignal gem installed and you are extending your jobs with "extend Appsignal::Integrations::ResquePlugin" The issue is that the ResquePlugin tries to write a socket to a tmp folder and Docker doesn't allow it. 如果您安装了AppSignal gem并且使用“extend Appsignal :: Integrations :: ResquePlugin”扩展您的作业,则会出现后续问题。问题是ResquePlugin尝试将套接字写入tmp文件夹而Docker不允许它。

I'm sure there is a Docker configuration to allow the socket to be written but I have instead created a development section in my appsignal.yml file and set the active flag to false. 我确定有一个Docker配置允许写入套接字,但我在我的appsignal.yml文件中创建了一个开发部分,并将活动标志设置为false。 The latest version of the Appsignal gem still attempts to write to the socket even when active = false. 即使active = false,最新版本的Appsignal gem仍会尝试写入套接字。 Version 0.13.0 of the gem (to be released tomorrow) should have a fix for this in place 宝石的版本0.13.0(将于明天发布)应该有一个固定的位置

appsignal.yml appsignal.yml

production:
  api_key: "xxxxxxxxxxxxxxxxxxxxxxxx"
  active: true
  slow_request_threshold: 200
staging:
  api_key: "xxxxxxxxxxxxxxxxxxxxxxxx"
  active: true
  slow_request_threshold: 200
development:
  api_key: "xxxxxxxxxxxxxxxxxxxxxxxx"
  active: false
  slow_request_threshold: 200

在resque的github页面https://github.com/resque/resque上 ,它提到你需要运行bin/resque work来开始轮询队列和启动worker。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM