Resque作业已处理但未执行任何操作

时间:2016-04-06 15:09:40

标签: ruby-on-rails-4 resque rails-activejob

我尝试使用resque在后台运行一个作业,然后在关注文档和几个教程之后我被困住了。运行resque.log它表示工作已经完成,但它确实没有。

我目前正在调用

这样的工作
Resque.enqueue(CsvImporterJob, params[:file].path, @organization.id)

这是工作:

class CsvImporterJob < ActiveJob::Base
  @queue = :import

  def self.perform(file, organization_id)
    CSV.foreach(file, :headers => true) do |row|
      if row
        user = row.to_hash
        email = user["email"]
        case user["role"].downcase
        when "admin"
          role_id = Role.admin
        else
          role_id = Role.user
        end
        ActivateHelper.send_activation_token(email, organization_id, role_id)
      end
    end
  end
end

这是日志:

D, [2016-04-06T11:02:59.854604 #6548] DEBUG -- : resque-1.25.2: Waiting for *
D, [2016-04-06T11:03:04.856115 #6548] DEBUG -- : Checking import
D, [2016-04-06T11:03:04.856388 #6548] DEBUG -- : Found job on import
I, [2016-04-06T11:03:04.856441 #6548]  INFO -- : got: (Job{import} | CsvImporterJob | ["/var/folders/92/87zkvh_53mb3721x4025vmsr0000gn/T/RackMultipart20160406-6422-1t7akw1.csv", 6])
D, [2016-04-06T11:03:04.856771 #6548] DEBUG -- : resque-1.25.2: Processing import since 1459954984 [CsvImporterJob]
I, [2016-04-06T11:03:04.856811 #6548]  INFO -- : Running before_fork hooks with [(Job{import} | CsvImporterJob | ["/var/folders/92/87zkvh_53mb3721x4025vmsr0000gn/T/RackMultipart20160406-6422-1t7akw1.csv", 6])]
D, [2016-04-06T11:03:04.858903 #6548] DEBUG -- : resque-1.25.2: Forked 6608 at 1459954984
I, [2016-04-06T11:03:04.859985 #6608]  INFO -- : Running after_fork hooks with [(Job{import} | CsvImporterJob | ["/var/folders/92/87zkvh_53mb3721x4025vmsr0000gn/T/RackMultipart20160406-6422-1t7akw1.csv", 6])]
I, [2016-04-06T11:03:04.865640 #6608]  INFO -- : done: (Job{import} | CsvImporterJob | ["/var/folders/92/87zkvh_53mb3721x4025vmsr0000gn/T/RackMultipart20160406-6422-1t7akw1.csv", 6])
D, [2016-04-06T11:03:04.869546 #6548] DEBUG -- : Checking import
D, [2016-04-06T11:03:04.869914 #6548] DEBUG -- : Sleeping for 5.0 seconds
D, [2016-04-06T11:03:04.869947 #6548] DEBUG -- : resque-1.25.2: Waiting for *
D, [2016-04-06T11:03:09.871048 #6548] DEBUG -- : Checking import
D, [2016-04-06T11:03:09.871237 #6548] DEBUG -- : Sleeping for 5.0 seconds
D, [2016-04-06T11:03:09.871459 #6548] DEBUG -- : resque-1.25.2: Waiting for *
D, [2016-04-06T11:03:14.872187 #6548] DEBUG -- : Checking import
D, [2016-04-06T11:03:14.872390 #6548] DEBUG -- : Sleeping for 5.0 seconds

我应该做的具体事情是什么?提前致谢

1 个答案:

答案 0 :(得分:0)

通过正确设置redis连接解决了这个问题

require 'resque/tasks'
require 'resque/scheduler/tasks'

task "resque:setup" => :environment do
  ENV['QUEUE'] = '*'

  Resque.redis = 'localhost:6379' unless Rails.env == 'production'

  Resque.before_fork = Proc.new do |job|
    ActiveRecord::Base.connection.disconnect!
  end
  Resque.after_fork = Proc.new do |job|
    ActiveRecord::Base.establish_connection
  end
end