Permalink
Browse files

using resque_mailer to background all email

some delayed jobs still need work
  • Loading branch information...
1 parent a61357d commit 47812c33ec69d42e42c3294b8b718ee10b23428d @ambtus ambtus committed Mar 18, 2011
Showing with 628 additions and 579 deletions.
  1. +4 −3 Gemfile
  2. +19 −11 Gemfile.lock
  3. +1 −0 Rakefile
  4. +2 −2 app/controllers/abuse_reports_controller.rb
  5. +33 −37 app/controllers/admin/admin_users_controller.rb
  6. +1 −5 app/controllers/challenge_assignments_controller.rb
  7. +1 −6 app/controllers/challenge_signups_controller.rb
  8. +2 −2 app/controllers/feedbacks_controller.rb
  9. +10 −10 app/controllers/passwords_controller.rb
  10. +1 −5 app/controllers/potential_matches_controller.rb
  11. +4 −4 app/controllers/users_controller.rb
  12. +11 −0 app/mailers/README
  13. +17 −14 app/mailers/admin_mailer.rb
  14. +23 −20 app/mailers/comment_mailer.rb
  15. +5 −3 app/mailers/kudo_mailer.rb
  16. +96 −77 app/mailers/user_mailer.rb
  17. +43 −43 app/models/challenge_assignment.rb
  18. +4 −3 app/models/challenge_signup.rb
  19. +81 −88 app/models/collection.rb
  20. +34 −33 app/models/collection_item.rb
  21. +32 −32 app/models/comment_observer.rb
  22. +17 −17 app/models/creation_observer.rb
  23. +26 −26 app/models/external_author.rb
  24. +16 −16 app/models/invitation.rb
  25. +1 −1 app/models/kudo_observer.rb
  26. +18 −17 app/models/potential_match.rb
  27. +15 −18 app/models/prompt_restriction.rb
  28. +5 −5 app/models/related_work.rb
  29. +8 −8 app/models/user_invite_request.rb
  30. +8 −8 app/models/work_observer.rb
  31. +5 −5 app/views/admin_mailer/archive_notification.html.erb
  32. +2 −2 app/views/user_mailer/archive_notification.html.erb
  33. +7 −7 app/views/user_mailer/claim_notification.html.erb
  34. +6 −6 app/views/user_mailer/invitation.html.erb
  35. +2 −2 app/views/user_mailer/reset_password.html.erb
  36. +13 −1 config.ru
  37. +9 −0 config/initializers/gem-plugin_config/resque.rb
  38. +1 −0 config/initializers/gem-plugin_config/resque_mailer.rb
  39. +2 −0 config/resque.yml
  40. +41 −41 features/admin_tasks.feature
  41. +2 −1 features/step_definitions/generic_steps.rb
View
@@ -26,13 +26,14 @@ gem 'nokogiri'
gem 'mechanize'
gem 'sanitize'
gem 'rest-client', :require => 'rest_client'
-gem 'delayed_job', '=2.1.1'
-gem 'daemons', '=1.0.10'
+gem 'resque', '>=1.14.0'
+gem 'resque_mailer'
+# https://github.com/defunkt/resque/issues/221
+gem 'sinatra', '~> 1.1.3'
gem 'thinking-sphinx',
:git => 'git://github.com/freelancing-god/thinking-sphinx.git',
:branch => 'rails3',
:require => 'thinking_sphinx'
-gem 'ts-delayed-delta', :require => 'thinking_sphinx/deltas/delayed_delta'
#gem 'daemon-spawn', :require => 'daemon_spawn'
gem 'aws-s3', :require => 'aws/s3'
# gem 'fastercsv' -- will use this eventually for exporting to excel tsv format
View
@@ -110,11 +110,7 @@ GEM
cucumber-rails (0.3.2)
cucumber (>= 0.8.0)
culerity (0.2.12)
- daemons (1.0.10)
database_cleaner (0.6.0.rc.3)
- delayed_job (2.1.1)
- activesupport (~> 3.0)
- daemons
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
@@ -166,7 +162,7 @@ GEM
rspec (>= 1.3)
yard
polyglot (0.3.1)
- rack (1.2.1)
+ rack (1.2.2)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-openid (1.2.0)
@@ -188,6 +184,15 @@ GEM
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
+ redis (2.1.1)
+ redis-namespace (0.10.0)
+ redis (< 3.0.0)
+ resque (1.14.0)
+ json (~> 1.4.6)
+ redis-namespace (>= 0.10.0)
+ sinatra (>= 0.9.2)
+ vegas (~> 0.1.2)
+ resque_mailer (1.0.1)
rest-client (1.6.1)
mime-types (>= 1.16)
riddle (1.2.1)
@@ -224,19 +229,22 @@ GEM
json_pure
rubyzip
shoulda (2.11.3)
+ sinatra (1.1.3)
+ rack (~> 1.1)
+ tilt (>= 1.2.2, < 2.0)
stringex (1.2.0)
term-ansicolor (1.0.5)
thor (0.14.6)
+ tilt (1.2.2)
treetop (1.4.9)
polyglot (>= 0.3.1)
- ts-delayed-delta (1.1.1)
- delayed_job (>= 1.8.4)
- thinking-sphinx (>= 1.3.6)
tzinfo (0.3.24)
unicorn (2.0.0)
kgio (~> 1.3.1)
rack
vcr (1.6.0)
+ vegas (0.1.8)
+ rack (>= 1.0.0)
whenever (0.6.2)
aaronh-chronic (>= 0.3.9)
activesupport (>= 2.3.4)
@@ -256,9 +264,7 @@ DEPENDENCIES
css_parser
cucumber (>= 0.9.1)
cucumber-rails
- daemons (= 1.0.10)
database_cleaner (>= 0.6.0.rc.3)
- delayed_job (= 2.1.1)
escape_utils
factory_girl
fakeweb
@@ -275,14 +281,16 @@ DEPENDENCIES
pickle
rack-openid (>= 0.2.1)
rails (= 3.0.4)
+ resque (>= 1.14.0)
+ resque_mailer
rest-client
rspec-rails (>= 2.0.0)
ruby-debug19
sanitize
shoulda
+ sinatra (~> 1.1.3)
thinking-sphinx!
tolk!
- ts-delayed-delta
unicorn
vcr
whenever (~> 0.6.2)
View
@@ -3,5 +3,6 @@
require File.expand_path('../config/application', __FILE__)
require 'rake'
+require 'resque/tasks'
Otwarchive::Application.load_tasks
@@ -29,11 +29,11 @@ def create
site['/projects/4603/bugs'].post build_post_info(@abuse_report), :content_type => 'application/xml', :accept => 'application/xml'
end
# Email bug to feedback email address
- AdminMailer.abuse_report(@abuse_report.email, @abuse_report.url, @abuse_report.comment).deliver
+ AdminMailer.abuse_report(@abuse_report.id).deliver
if params[:cc_me]
# If user requests, and supplies email address, email them a copy of their message
if !@abuse_report.email.blank?
- UserMailer.abuse_report(@abuse_report).deliver
+ UserMailer.abuse_report(@abuse_report.id).deliver
else
flash[:error] = t('no_email', :default => "Sorry, we can only send you a copy of your abuse report if you enter a valid email address.")
format.html { render :action => "new" }
@@ -1,5 +1,5 @@
class Admin::AdminUsersController < ApplicationController
-
+
before_filter :admin_only
def index
@@ -10,8 +10,8 @@ def index
elsif params[:role] == "0"
joins = :pseuds
conditions = ['pseuds.name LIKE ? OR email = ?', "%#{params[:query]}%", params[:query]]
- elsif params[:role] == "1"
- if !params[:query].blank?
+ elsif params[:role] == "1"
+ if !params[:query].blank?
joins = :pseuds
conditions = [('(pseuds.name LIKE ? OR email = ?) AND activated_at IS NULL'), "%#{params[:query]}%", params[:query]]
else
@@ -22,7 +22,7 @@ def index
joins = [:pseuds, :roles]
conditions = ['(pseuds.name LIKE ? OR email = ?) AND roles.name = ?', "%#{params[:query]}%", params[:query], params[:role]]
else
- joins = :roles
+ joins = :roles
conditions = ['roles.name = ?', params[:role]]
end
end
@@ -37,7 +37,7 @@ def show
@user = User.find_by_login(params[:id])
unless @user
redirect_to :action => "index", :query => params[:query], :role => params[:role]
- end
+ end
@log_items = @user.log_items.sort_by(&:created_at).reverse
end
@@ -59,7 +59,7 @@ def update_user
else
flash[:error] = ts('There was an error updating user %{name}', :name => params[:id])
redirect_to(request.env["HTTP_REFERER"] || root_path)
- end
+ end
elsif params[:admin_action]
@user = User.find_by_login(params[:user_login])
@admin_note = params[:admin_note]
@@ -69,7 +69,7 @@ def update_user
else
if params[:admin_action] == 'warn'
@user.create_log_item( options = {:action => ArchiveConfig.ACTION_WARN, :note => @admin_note, :admin_id => current_admin.id})
- flash[:notice] = ts("Warning was recorded")
+ flash[:notice] = ts("Warning was recorded")
redirect_to(request.env["HTTP_REFERER"] || root_path)
elsif params[:admin_action] == 'suspend'
if params[:suspend_days].blank?
@@ -81,21 +81,21 @@ def update_user
@user.suspended_until = @suspension_days.days.from_now
if @user.save && @user.suspended? && !@user.suspended_until.blank?
@user.create_log_item( options = {:action => ArchiveConfig.ACTION_SUSPEND, :note => @admin_note, :admin_id => current_admin.id, :enddate => @user.suspended_until})
- flash[:notice] = ts("User has been temporarily suspended")
+ flash[:notice] = ts("User has been temporarily suspended")
redirect_to(request.env["HTTP_REFERER"] || root_path)
else
- flash[:error] = ts("User could not be suspended")
+ flash[:error] = ts("User could not be suspended")
redirect_to(request.env["HTTP_REFERER"] || root_path)
end
end
elsif params[:admin_action] == 'ban'
@user.banned = true
if @user.save && @user.banned?
@user.create_log_item( options = {:action => ArchiveConfig.ACTION_BAN, :note => @admin_note, :admin_id => current_admin.id})
- flash[:notice] = t('success_banned', :default => "User has been permanently suspended")
+ flash[:notice] = t('success_banned', :default => "User has been permanently suspended")
redirect_to(request.env["HTTP_REFERER"] || root_path)
- else
- flash[:error] = t('error_banned', :default => "User could not be permanently suspended")
+ else
+ flash[:error] = t('error_banned', :default => "User could not be permanently suspended")
redirect_to(request.env["HTTP_REFERER"] || root_path)
end
elsif params[:admin_action] == 'unsuspend'
@@ -104,29 +104,29 @@ def update_user
@user.suspended_until = nil
if @user.save && !@user.suspended? && @user.suspended_until.blank?
@user.create_log_item( options = {:action => ArchiveConfig.ACTION_UNSUSPEND, :note => @admin_note, :admin_id => current_admin.id})
- flash[:notice] = t('success_unsuspend', :default => "Suspension has been lifted")
+ flash[:notice] = t('success_unsuspend', :default => "Suspension has been lifted")
redirect_to(request.env["HTTP_REFERER"] || root_path)
else
- flash[:error] = t('error_unsuspend', :default => "Suspension could not be lifted")
+ flash[:error] = t('error_unsuspend', :default => "Suspension could not be lifted")
redirect_to(request.env["HTTP_REFERER"] || root_path)
end
else
- flash[:notice] = t('not_suspended', :default => "User had not been suspended")
+ flash[:notice] = t('not_suspended', :default => "User had not been suspended")
redirect_to(request.env["HTTP_REFERER"] || root_path)
end
elsif params[:admin_action] == 'unban'
if @user.banned?
@user.banned = false
if @user.save && !@user.banned?
@user.create_log_item( options = {:action => ArchiveConfig.ACTION_UNSUSPEND, :note => @admin_note, :admin_id => current_admin.id})
- flash[:notice] = t('success_unsuspend', :default => "Suspension has been lifted")
+ flash[:notice] = t('success_unsuspend', :default => "Suspension has been lifted")
redirect_to(request.env["HTTP_REFERER"] || root_path)
else
- flash[:error] = t('error_unsuspend', :default => "Suspension could not be lifted")
+ flash[:error] = t('error_unsuspend', :default => "Suspension could not be lifted")
redirect_to(request.env["HTTP_REFERER"] || root_path)
end
else
- flash[:notice] = t('not_banned', :default => "User had not been permanently suspended")
+ flash[:notice] = t('not_banned', :default => "User had not been permanently suspended")
redirect_to(request.env["HTTP_REFERER"] || root_path)
end
end
@@ -139,9 +139,9 @@ def update_user
def destroy
@user = User.find_by_login(params[:id])
@user.destroy
- redirect_to(admin_users_url)
+ redirect_to(admin_users_url)
end
-
+
def notify
if params[:letter] && params[:letter].is_a?(String)
letter = params[:letter][0,1]
@@ -150,7 +150,7 @@ def notify
end
@all_users = User.alphabetical.starting_with(letter)
end
-
+
def send_notification
if !params[:notify_all].blank?
if params[:notify_all].include?("0")
@@ -164,37 +164,33 @@ def send_notification
elsif params[:user_ids]
@users = User.find(params[:user_ids])
end
-
+
if @users.nil? || @users.length == 0
flash[:error] = ts("Who did you want to notify?")
redirect_to :action => :notify and return
end
-
+
unless params[:subject] && !params[:subject].blank?
flash[:error] = ts("Please enter a subject.")
redirect_to :action => :notify and return
else
@subject = params[:subject]
end
-
+
# We need to use content because otherwise html will be stripped
unless params[:content] && !params[:content].blank?
flash[:error] = ts("What message did you want to send?")
redirect_to :action => :notify and return
else
@message = params[:content]
end
-
+
@users.each do |user|
- if ArchiveConfig.NO_DELAYS
- UserMailer.archive_notification(current_admin.login, user, @subject, @message).deliver
- else
- UserMailer.delay.archive_notification(current_admin.login, user, @subject, @message)
- end
+ UserMailer.archive_notification(current_admin.login, user.id, @subject, @message).deliver
end
-
- AdminMailer.archive_notification(current_admin.login, @users, @subject, @message).deliver
-
+
+ AdminMailer.archive_notification(current_admin.login, @users.map(&:id), @subject, @message).deliver
+
flash[:notice] = ts("Notification sent to %{count} user(s).", :count => @users.size)
redirect_to :action => :notify
end
@@ -204,20 +200,20 @@ def activate
@user.activate
if @user.active?
@user.create_log_item( options = {:action => ArchiveConfig.ACTION_ACTIVATE, :note => 'Manually Activated', :admin_id => current_admin.id})
- flash[:notice] = t('activated', :default => "User Account Activated")
+ flash[:notice] = t('activated', :default => "User Account Activated")
redirect_to :action => :show
else
flash[:error] = t('activation_failed', :default => "Attempt to activate account failed.")
redirect_to :action => :show
end
end
-
+
def send_activation
@user = User.find_by_login(params[:id])
- UserMailer.signup_notification(@user).deliver
+ UserMailer.signup_notification(@user.id).deliver
flash[:notice] = t('activation_sent', :default => "Activation email sent")
redirect_to :action => :show
end
-end
+end
@@ -163,11 +163,7 @@ def send_out
# purge the potential matches! we don't want bazillions of them in our db
PotentialMatch.clear!(@collection)
- if ArchiveConfig.NO_DELAYS
- ChallengeAssignment.send_out!(@collection)
- else
- ChallengeAssignment.delay.send_out!(@collection)
- end
+ ChallengeAssignment.send_out!(@collection)
flash[:notice] = "Assignments are now being sent out."
redirect_to collection_assignments_path(@collection)
end
@@ -130,12 +130,7 @@ def summary
FileUtils.touch(ChallengeSignup.summary_file(@collection))
# generate the page
- if ArchiveConfig.NO_DELAYS
- ChallengeSignup.generate_summary(@collection)
- else
- # start a delayed job to generate the page
- ChallengeSignup.delay.generate_summary(@collection)
- end
+ ChallengeSignup.generate_summary(@collection)
end
else
# generate it on the fly
@@ -23,10 +23,10 @@ def create
site['/projects/4911/bugs'].post build_post_info(@feedback), :content_type => 'application/xml', :accept => 'application/xml'
end
# Email bug to feedback email address
- AdminMailer.feedback(@feedback).deliver
+ AdminMailer.feedback(@feedback.id).deliver
# If user supplies email address, email them an auto-response
if !@feedback.email.blank?
- UserMailer.feedback(@feedback).deliver
+ UserMailer.feedback(@feedback.id).deliver
end
flash[:notice] = t('successfully_sent', :default => 'Your message was sent to the archive team - thank you!')
format.html { redirect_back_or_default(root_path) }
Oops, something went wrong. Retry.

0 comments on commit 47812c3

Please sign in to comment.