如何让Sidekiq工作人员在Heroku上运行

Nic*_*ill 3 ruby-on-rails heroku sidekiq

我用我的Rails项目设置了Sidekiq.它与独角兽一起在Heroku上运行.我已经完成了所有配置步骤,包括设置正确的REDISTOGO_URL(如此问题引用),我已将以下内容添加到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
Run Code Online (Sandbox Code Playgroud)

我的Procfile如下:

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec sidekiq
Run Code Online (Sandbox Code Playgroud)

现在我将我的worker称为perform_async,它将任务添加到队列中.事实上,在我的Sidekiq网络界面中,它说队列中有7个项目,并且它包含所有数据.然而,没有工人处理队列和我的生活,我无法弄清楚为什么.如果我跑

heroku ps
Run Code Online (Sandbox Code Playgroud)

我得到以下输出:

=== 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)
Run Code Online (Sandbox Code Playgroud)

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

更新

这是我的工人类的代码.是的,我知道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
Run Code Online (Sandbox Code Playgroud)

Bil*_*ver 6

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

这是一个示例sidekiq.yml文件