完成作业截止定时发送消息

This commit is contained in:
huang 2015-09-10 17:37:25 +08:00
parent 6b0432c04c
commit 92a3d78dcc
4 changed files with 41 additions and 8 deletions

View File

@ -34,8 +34,10 @@ class Mailer < ActionMailer::Base
end
def method_missing(name, *args, &block)
if Setting.delayjob_enabled? && Object.const_defined?('Delayed')
# with delayed_job
@target.delay.send(name, *args, &block)
else
# without delayed_job
@target.send(name, *args, &block).deliver
end
end

View File

@ -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

View File

@ -202,13 +202,5 @@ END_DESC
Mailer.run.send_for_user_activities(user, Date.today, 1)
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

View File

@ -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