Skip to content

Commit a38790a

Browse files
committed
Merge pull request #120 from helpyio/dev/delay-jobs
Dev/delay jobs
2 parents 5927660 + 075029e commit a38790a

File tree

9 files changed

+19
-4
lines changed

9 files changed

+19
-4
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ gem 'ranked-model'
3434
gem 'staccato'
3535

3636
gem "rails-settings-cached"
37+
gem 'sucker_punch', '~> 2.0'
3738

3839
# Auth Gems
3940
gem 'devise'

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ GEM
422422
activesupport (>= 4.0)
423423
sprockets (>= 3.0.0)
424424
staccato (0.4.5)
425+
sucker_punch (2.0.1)
426+
concurrent-ruby (~> 1.0.0)
425427
temple (0.7.6)
426428
terminal-table (1.5.2)
427429
thor (0.19.1)
@@ -540,6 +542,7 @@ DEPENDENCIES
540542
shoulda
541543
spring (~> 1.4.0)
542544
staccato
545+
sucker_punch (~> 2.0)
543546
timecop
544547
trix
545548
turbolinks

app/controllers/admin_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def create_ticket
147147
:screenshots => params[:topic][:screenshots])
148148

149149
# Send email
150-
UserMailer.new_user(@user, @token).deliver_now
150+
UserMailer.new_user(@user, @token).deliver_later
151151

152152
# track event in GA
153153
@tracker.event(category: 'Request', action: 'Post', label: 'New Topic')

app/controllers/posts_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def send_message
179179
end
180180

181181
I18n.with_locale(email_locale) do
182-
TopicMailer.new_ticket(@post.topic).deliver_now if @topic.private?
182+
TopicMailer.new_ticket(@post.topic).deliver_later if @topic.private?
183183
end
184184
else
185185
logger.info("reply is not from admin, don't email") #might want to cchange this if we want admin notification emails

app/controllers/topics_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def create
186186
:screenshots => params[:topic][:screenshots])
187187

188188
if built_user == true && !user_signed_in?
189-
UserMailer.new_user(@user, @token).deliver_now
189+
UserMailer.new_user(@user, @token).deliver_later
190190
end
191191

192192
# track event in GA

config/application.rb

+4
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ class Application < Rails::Application
2626
# Do not swallow errors in after_commit/after_rollback callbacks.
2727
config.active_record.raise_in_transactional_callbacks = true
2828

29+
# We are using active_job and currently the inline backend. You may change this if
30+
# you want a more robust solution. The queue is used for emails.
31+
config.active_job.queue_adapter = :sucker_punch
32+
2933
end
3034
end

config/initializers/sucker_punch.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# config/initializers/sucker_punch.rb
2+
3+
require 'sucker_punch/async_syntax'

lib/email_processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def create_user
6969
@user.name = @email.from[:name].blank? ? @email.from[:token] : @email.from[:name]
7070
@user.password = User.create_password
7171
if @user.save
72-
UserMailer.new_user(@user, @token).deliver_now
72+
UserMailer.new_user(@user, @token).deliver_later
7373
end
7474
end
7575
end

test/test_helper.rb

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
require File.expand_path('../../config/environment', __FILE__)
55
require 'rails/test_help'
66

7+
# Requiring this library causes your jobs to run everything inline. So a call to the following
8+
# will actually be SYNCHRONOUS
9+
require 'sucker_punch/testing/inline'
10+
711
class ActiveSupport::TestCase
812
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
913
fixtures :all

0 commit comments

Comments
 (0)