代码之家  ›  专栏  ›  技术社区  ›  ikbenben

码头工人+铁路+redis-救援人员未运行

  •  3
  • ikbenben  · 技术社区  · 11 年前

    我创建了一个docker环境,它创建了3个图像:rails、postgresql和redis。它一直运行得很好,但我发现我的redis图像似乎没有任何工人在运行。

    Docker信息

    我的码头工人作曲。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配置

    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
    

    红宝石宝石

    以下是使用的相关宝石。注释掉的版本是gems的最新版本,但我不认为这是一个问题,因为当前版本在Heroku环境中运行良好。我还包括救援邮件和调度程序,以确保彻底性。他们不适合这个问题

    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'
    

    测试信息

    我已经确认通过远程登录到端口6379上的redis主机,可以从web容器访问redis。我还输出了Rescue的值。显示有项目排队但现在工作人员正在运行的信息

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

    我陷入了这一点,因为我不知道如何让工人们运转起来。有什么建议吗?

    2 回复  |  直到 11 年前
        1
  •  6
  •   ikbenben    11 年前

    我能够通过包括一个基于web图像的新图像来解决这个问题。我的新码头工人作曲。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
    
    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"
    

    如果您安装了AppSignal gem,并且使用“extend AppSignal::Integrations::ResquePlugin”扩展作业,则会出现后续问题。问题是ResquePlug-in试图将套接字写入tmp文件夹,Docker不允许这样做。

    我确信有一个Docker配置允许编写套接字,但我在appsignal中创建了一个开发部分。yml文件,并将活动标志设置为false。即使active=false,最新版本的Appsignal gem仍会尝试写入套接字。gem的0.13.0版本(将于明天发布)应该对此进行了修复

    应用信号.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
    
        2
  •  1
  •   rottweilers_anonymous    11 年前

    在resque的github页面上 https://github.com/resque/resque ,它提到你需要跑步 bin/resque work 开始轮询队列并启动工作程序。