使用rake批处理任务

08 Nov 2013, by

多线程执行rake

(0..49).to_a.each do |num|
  system "cd /u/apps/haha/current & bundle exec rake check_error_list
 num=#{num} RAILS_ENV=production >/dev/null 2>&1 &"
  sleep(2)
end
  desc "处理抓取过程中出错的状态为8的漫画"
  task :check_error_list => :environment do
    this_num = ENV['num']
    ActiveRecord::Base.establish_connection
    puts "run id%50 = #{this_num}"
    Info.where(servertype: 8).where("www_92game_net_7k7kmanhua_ecms_info.id % 50 = #{this_num}").readonly(false).each do |info|
      info.offline.destroy
      info.status = "pending"
      archive = ArchiveOffline::Archive.new info
      archive.archive_file
    end
  end