desc "开放课程开课前通知报名用户" namespace :public_course_notice do task :tiding => :environment do Course.where(excellent: 1).where("start_date is not null and start_date = '#{Date.today}'").each do |course| attrs = %i[user_id trigger_user_id status container_id container_type belong_container_id belong_container_type tiding_type created_at updated_at] same_attrs = { trigger_user_id: 0, container_id: course.id, container_type: 'PublicCourseStart', belong_container_id: course.id, belong_container_type: 'Course', tiding_type: 'System', status: 0 } Tiding.bulk_insert(*attrs) do |worker| course.students.each do |student| worker.add same_attrs.merge(user_id: student.user_id) end end end end end