Skip to content

Commit

Permalink
Merge pull request #120 from helpyio/dev/delay-jobs
Browse files Browse the repository at this point in the history
Dev/delay jobs
  • Loading branch information
scott committed Apr 18, 2016
2 parents 5927660 + 075029e commit a38790a
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ gem 'ranked-model'
gem 'staccato'

gem "rails-settings-cached"
gem 'sucker_punch', '~> 2.0'

# Auth Gems
gem 'devise'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -540,6 +542,7 @@ DEPENDENCIES
shoulda
spring (~> 1.4.0)
staccato
sucker_punch (~> 2.0)
timecop
trix
turbolinks
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/initializers/sucker_punch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# config/initializers/sucker_punch.rb

require 'sucker_punch/async_syntax'
2 changes: 1 addition & 1 deletion lib/email_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a38790a

Please sign in to comment.