# 任务发布 消息通知 class GraduationTaskPublishNotifyJob < ApplicationJob queue_as :notify def perform(graduation_task_id) task = GraduationTask.find_by(id: graduation_task_id) return if task.blank? attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type belong_container_id belong_container_type viewed tiding_type created_at updated_at ] same_attrs = { trigger_user_id: task.user_id, container_id: task.id, container_type: 'GraduationTask', parent_container_id: task.id, parent_container_type: 'TaskPublish', belong_container_id: task.course_id, belong_container_type: 'Course', viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| task.course.students.find_each do |student| worker.add same_attrs.merge(user_id: student.user_id) end end end end