namespace :live_notice do
  desc "send a live message to students before 30 minutes"
  task message: :environment do
    lives = LiveLink.where(on_status: 0).where("live_time <= '#{Time.now + 30*60}' and live_time > '#{Time.now}'")
    lives.each do |live|
      LivePublishJob.perform_later(live.id)
    end
  end

  task on_status: :environment do
    LiveLink.where(on_status: 0).where("live_time <= '#{Time.now}'").update_all(on_status: 1)
  end
end