【问题标题】:Resque job is processed but not doing anythingResque 作业已处理但未执行任何操作
【发布时间】:2016-04-06 15:09:39
【问题描述】:

我正在尝试使用 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

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

【问题讨论】:

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


    【解决方案1】:

    通过正确设置与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
    

    【讨论】:

      猜你喜欢
      • 2014-01-05
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 2011-07-26
      • 2011-10-19
      相关资源
      最近更新 更多