namespace :myshixun do task check_reponame: :environment do # 如果是选择题的则跳过,否则reponame 为空的则为异常 myshixuns = Myshixun.where("repo_name is null and created_at > '2019-07-20 00:00:00'") myshixuns.each do |myshixun| shixun = myshixun.shixun challenges = shixun.challenges # 不是纯选择题的情况 if challenges.select{|challenge| challenge.st.to_i == 0}.size > 0 puts myshixun.games.first.try(:identifier) end end end task choose_repo: :environment do myshixuns = Myshixun.where("repo_name is null and created_at > '2019-07-20 00:00:00'") myshixuns.each do |myshixun| shixun = myshixun.shixun challenges = shixun.challenges # 如果是选择题,则把myshixuns表的repo_name改成-1 if challenges.select{|challenge| challenge.st.to_i == 1}.size == challenges.count myshixun.update_attributes(:repo_name => "-1") end end end end