diff --git a/Gemfile b/Gemfile index b84afa1c0..b7736fa8d 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ gem 'ranked-model' gem 'staccato' gem "rails-settings-cached" +gem 'sucker_punch', '~> 2.0' # Auth Gems gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index 398fa8d34..5c8bb27f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -422,6 +422,8 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) staccato (0.4.5) + sucker_punch (2.0.1) + concurrent-ruby (~> 1.0.0) temple (0.7.6) terminal-table (1.5.2) thor (0.19.1) @@ -540,6 +542,7 @@ DEPENDENCIES shoulda spring (~> 1.4.0) staccato + sucker_punch (~> 2.0) timecop trix turbolinks diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 4c8d6415a..433b13c72 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -147,7 +147,7 @@ def create_ticket :screenshots => params[:topic][:screenshots]) # Send email - UserMailer.new_user(@user, @token).deliver_now + UserMailer.new_user(@user, @token).deliver_later # track event in GA @tracker.event(category: 'Request', action: 'Post', label: 'New Topic') diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d73671b3b..3225e9152 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -179,7 +179,7 @@ def send_message end I18n.with_locale(email_locale) do - TopicMailer.new_ticket(@post.topic).deliver_now if @topic.private? + TopicMailer.new_ticket(@post.topic).deliver_later if @topic.private? end else logger.info("reply is not from admin, don't email") #might want to cchange this if we want admin notification emails diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index bb80f8368..33cb47729 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -186,7 +186,7 @@ def create :screenshots => params[:topic][:screenshots]) if built_user == true && !user_signed_in? - UserMailer.new_user(@user, @token).deliver_now + UserMailer.new_user(@user, @token).deliver_later end # track event in GA diff --git a/config/application.rb b/config/application.rb index a2b789f48..a5663e055 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,5 +26,9 @@ class Application < Rails::Application # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true + # We are using active_job and currently the inline backend. You may change this if + # you want a more robust solution. The queue is used for emails. + config.active_job.queue_adapter = :sucker_punch + end end diff --git a/config/initializers/sucker_punch.rb b/config/initializers/sucker_punch.rb new file mode 100644 index 000000000..f41fb3159 --- /dev/null +++ b/config/initializers/sucker_punch.rb @@ -0,0 +1,3 @@ +# config/initializers/sucker_punch.rb + +require 'sucker_punch/async_syntax' diff --git a/lib/email_processor.rb b/lib/email_processor.rb index 823f8a166..219d0852d 100644 --- a/lib/email_processor.rb +++ b/lib/email_processor.rb @@ -69,7 +69,7 @@ def create_user @user.name = @email.from[:name].blank? ? @email.from[:token] : @email.from[:name] @user.password = User.create_password if @user.save - UserMailer.new_user(@user, @token).deliver_now + UserMailer.new_user(@user, @token).deliver_later end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index cfbfa3358..8709323a9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,10 @@ require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' +# Requiring this library causes your jobs to run everything inline. So a call to the following +# will actually be SYNCHRONOUS +require 'sucker_punch/testing/inline' + class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all