完成作业截止定时发送消息
This commit is contained in:
parent
6b0432c04c
commit
92a3d78dcc
|
@ -34,8 +34,10 @@ class Mailer < ActionMailer::Base
|
||||||
end
|
end
|
||||||
def method_missing(name, *args, &block)
|
def method_missing(name, *args, &block)
|
||||||
if Setting.delayjob_enabled? && Object.const_defined?('Delayed')
|
if Setting.delayjob_enabled? && Object.const_defined?('Delayed')
|
||||||
|
# with delayed_job
|
||||||
@target.delay.send(name, *args, &block)
|
@target.delay.send(name, *args, &block)
|
||||||
else
|
else
|
||||||
|
# without delayed_job
|
||||||
@target.send(name, *args, &block).deliver
|
@target.send(name, *args, &block).deliver
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
#coding=utf-8
|
||||||
|
#
|
||||||
|
|
||||||
|
class HomeworkEndtimeTask
|
||||||
|
def massage_for_endtime
|
||||||
|
desc "send a message for Job deadline"
|
||||||
|
task :message => :environment do
|
||||||
|
current_day = Date.today.day
|
||||||
|
homework_commons = HomeworkCommon.where("end_time >?",Date.today)
|
||||||
|
homework_commons.each do |homework_common|
|
||||||
|
if homework_common.end_time.day - Date.today < 2 && homework_common.end_time.year == Date.year
|
||||||
|
homework_common.course.student.each do |s|
|
||||||
|
homework_common.course_messages << CourseMessage.new(:user_id => s.student_id, :course_id => homework_common.course_id, :viewed => false, :course_message_id => homework_common.id, :course_message_type => "HomeworkEndtime")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
handle_asynchronously :massage_for_endtime, :run_at => HomeworkEndtimeTask.new { 1.minutes.from_now }
|
||||||
|
end
|
||||||
|
|
||||||
|
homwork_endtime = HomeworkEndtimeTask.new
|
||||||
|
homwork_endtime.massage_for_endtime
|
||||||
|
end
|
|
@ -202,13 +202,5 @@ END_DESC
|
||||||
Mailer.run.send_for_user_activities(user, Date.today, 1)
|
Mailer.run.send_for_user_activities(user, Date.today, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "send a message for Job deadline"
|
|
||||||
task :message => :environment do
|
|
||||||
users = User.where(mail_notification: 'day')
|
|
||||||
users.each do |user|
|
|
||||||
Mailer.run.send_for_user_activities(user, Date.today, 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
namespace :homework_endtime do
|
||||||
|
desc "send a message for Job deadline"
|
||||||
|
task :message => :environment do
|
||||||
|
current_day = Date.today.day
|
||||||
|
homework_commons = HomeworkCommon.where("end_time >?",Date.today)
|
||||||
|
homework_commons.each do |homework_common|
|
||||||
|
if homework_common.end_time.day - Date.today.day < 2 && homework_common.end_time.year == Date.today.year
|
||||||
|
homework_common.course.student.each do |s|
|
||||||
|
homework_common.course_messages << CourseMessage.new(:user_id => s.student_id, :course_id => homework_common.course_id, :viewed => false, :status => true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue