From 92a3d78dcc73d9863cd69b4773613bc3308cc3ee Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 10 Sep 2015 17:37:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=88=AA=E6=AD=A2=E5=AE=9A=E6=97=B6=E5=8F=91=E9=80=81=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/mailer.rb | 2 ++ app/tasks/homework_endtime_task.rb | 23 +++++++++++++++++++++++ lib/tasks/email.rake | 8 -------- lib/tasks/homework_endtime.rake | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 app/tasks/homework_endtime_task.rb create mode 100644 lib/tasks/homework_endtime.rake diff --git a/app/models/mailer.rb b/app/models/mailer.rb index a25aff6bb..4fe2478d2 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -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 diff --git a/app/tasks/homework_endtime_task.rb b/app/tasks/homework_endtime_task.rb new file mode 100644 index 000000000..9b3d6e2ef --- /dev/null +++ b/app/tasks/homework_endtime_task.rb @@ -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 diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake index f805d1382..5126d7a69 100644 --- a/lib/tasks/email.rake +++ b/lib/tasks/email.rake @@ -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 diff --git a/lib/tasks/homework_endtime.rake b/lib/tasks/homework_endtime.rake new file mode 100644 index 000000000..9c7f54d75 --- /dev/null +++ b/lib/tasks/homework_endtime.rake @@ -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 From cc3990de444239bde1d363043b2d624fed4fdfb3 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 11 Sep 2015 09:45:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=91=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=B6=88=E6=81=AF=E5=90=8E=E8=B7=B3=E8=BD=AC=E8=B7=AF?= =?UTF-8?q?=E5=8A=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/system_messages_controller.rb | 2 +- app/tasks/homework_endtime_task.rb | 23 ------------------- config/routes.rb | 1 - 3 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 app/tasks/homework_endtime_task.rb diff --git a/app/controllers/system_messages_controller.rb b/app/controllers/system_messages_controller.rb index 588e13c5e..ae49b58a8 100644 --- a/app/controllers/system_messages_controller.rb +++ b/app/controllers/system_messages_controller.rb @@ -42,7 +42,7 @@ class SystemMessagesController < ApplicationController @system_messages.user_id = User.current.id respond_to do |format| if @system_messages.save - format.html {redirect_to system_messages_url(@project)} + format.html {redirect_to user_message_path(User.current, :type => "system_message")} flash[:notice] = l(:notice_successful_message) end end diff --git a/app/tasks/homework_endtime_task.rb b/app/tasks/homework_endtime_task.rb deleted file mode 100644 index 9b3d6e2ef..000000000 --- a/app/tasks/homework_endtime_task.rb +++ /dev/null @@ -1,23 +0,0 @@ -#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 diff --git a/config/routes.rb b/config/routes.rb index 2a0e1a492..1df7b0d2f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -265,7 +265,6 @@ RedmineApp::Application.routes.draw do collection do post 'create', :as => 'system_messages' get 'index', :as => 'index' - get 'show', :as => 'show' end end # match 'system_messages/index', to: 'system_messages#index', :via => :get, :as => 'system_messages'