多线程执行rake
-
利用表的id取膜运算实现
-
在xx.rb中写入:
(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
- 在rake中写入:
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