【问题标题】:How to get Sidekiq workers running on Heroku如何让 Sidekiq 工作人员在 Heroku 上运行
【发布时间】:2012-12-09 16:15:46
【问题描述】:

我已经使用我的 Rails 项目设置了 Sidekiq。它与 Unicorn 在 Heroku 上运行。我已经完成了所有配置步骤,包括设置正确的 REDISTOGO_URL (as this question references),我在 unicorn.rb 中的 after_fork 中添加了以下内容:

after_fork do |server,worker|
    if defined?(ActiveRecord::Base)
        ActiveRecord::Base.establish_connection
        Rails.logger.info('Connected to ActiveRecord')
    end

    Sidekiq.configure_client do |config|
        config.redis = { :size => 1 }
    end
end

我的Procfile如下:

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec sidekiq

现在我调用我的工作人员来 perform_async 并将任务添加到队列中。事实上,在我的 Sidekiq Web 界面中,它说队列中有 7 个项目,并且那里有所有数据。然而,没有工作人员处理队列,对于我的生活,我无法弄清楚为什么。如果我运行

heroku ps

我得到以下输出:

=== web: `bundle exec unicorn -p $PORT -c ./config/unicorn.rb`
web.1: up 2012/12/09 08:04:24 (~ 9m ago)

=== worker: `bundle exec sidekiq`
worker.1: up 2012/12/09 08:04:08 (~ 10m ago)

有人知道这里发生了什么吗?

更新

这是我的工人阶级的代码。是的,我知道 Oj gem 可能与 sidekiq 存在一些问题,但我想我会先试一试。此时我没有收到任何错误消息(工作人员甚至没有运行)。

require 'addressable/uri'
class DatasiftInteractionsWorker
include Sidekiq::Worker
sidekiq_options queue: "tweets"

def perform( stream_id , interactions )
    interactions = Oj.load(interactions)
    interactions.each{ |interaction|
        if interaction['interaction']['type'] == 'twitter'
            url = interaction['links']['normalized_url'] unless interaction['links']['normalized_url'][0].nil?
            url = interaction['links']['url'] if interaction['links']['normalized_url'][0].nil?
            begin
                puts interaction['links'] if url[0].nil?
                next if url[0].nil?
                host = Addressable::URI.parse(url[0]).host
                host = host.gsub(/^www\.(.*)$/,'\1')
                date_str = Time.now.strftime('%Y%m%d')
                REDIS.pipelined do
                    # Add domain to Redis domains Set
                    REDIS.sadd date_str , host
                    # INCR Redis host
                    REDIS.incr( host + date_str )
                end
            rescue
                puts "ERROR: Could not store the following links: " + interaction['links'].to_s
            end
        end
    }
end
end

【问题讨论】:

  • 你在你的 Heroku 日志中看到任何关于 [worker.1] 的内容吗?类似heroku logs -t | grep worker.1(然后是 perform_async)
  • 假设您使用的是免费计划,那么这意味着您只能访问一名工作人员。
  • @JesseWolgamott 是的,它已启动:2012-12-09T16:04:08+00:00 heroku[worker.1]:进程以状态 0 退出 2012-12-09T16:04:08+ 00:00 heroku[worker.1]:状态从开始变为向上
  • @JesseWolgamott 在运行 perform_async 后没有任何反应......它只是添加到队列中,但工作人员从不运行
  • @JesseWolgamott 在经历这个过程时,我想我刚刚弄明白了......因为我使用的是自定义队列名称,所以它没有在该队列中加载项目

标签: ruby-on-rails heroku sidekiq


【解决方案1】:

我的偏好是创建一个 /config/sidekiq.yml 文件,然后在您的 Procfile 中使用 worker: bundle exec sidekiq -C config/sidekiq.yml

Here's 示例 sidekiq.yml 文件

【讨论】:

    【解决方案2】:

    发现如果您使用的是自定义队列,则需要让 Sidekiq 在 Procfile 中了解该队列,如下所示:

    worker: bundle exec sidekiq -q tweets, 1 -q default
    

    我不太清楚为什么会这样,因为 sidekiq 知道所有队列。我将把它作为一个问题发布在 Sidekiq 项目上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      相关资源
      最近更新 更多