发布问卷的消息通知放delay_job
This commit is contained in:
parent
fb810a1993
commit
28c5e9dfcc
|
@ -57,15 +57,32 @@ class Poll < ActiveRecord::Base
|
|||
def act_as_course_message
|
||||
if self.polls_type == "Course"
|
||||
if self.polls_status == 2 #问卷是发布状态
|
||||
vs = []
|
||||
Course.find(self.polls_group_id).members.each do |m|
|
||||
if m.user_id != self.user_id
|
||||
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.polls_group_id, :viewed => false)
|
||||
vs << {course_message_type:'Poll',course_message_id:self.id, :user_id => m.user_id,
|
||||
:course_id => self.polls_group_id, :viewed => false}
|
||||
|
||||
#delayed_job卡住的原因是一次执行的条数太多,导致超时。
|
||||
#现在把每次只执行不超过30条,就不会超了。
|
||||
if vs.size >= 30
|
||||
self.delay.contain_poll_message(vs)
|
||||
vs.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless vs.empty?
|
||||
self.delay.contain_poll_message(vs)
|
||||
end
|
||||
|
||||
elsif self.polls_status == 1 #问卷是新建状态
|
||||
self.course_messages.destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def contain_poll_message(vs)
|
||||
CourseMessage.create(vs)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue