Reputation: 2938
user_controller.rb
class UsersController
def create
MyJob.perform_later
User.create(...)
end
end
my_job.rb
class MyJob < ActiveJob::Base
queue_as :default
def perform()
puts "START"
sleep 3
puts "END"
end
end
config/initializer/sucker_punch.rb
require 'sucker_punch/async_syntax'
Rails.application.configure do
config.active_job.queue_adapter = :sucker_punch
end
When I run MyJob.perform_later
in a rails console, everything work fine and the logger display this message Enqueued MyJob (Job ID: 6c857af8-a8ed-4bd0-918b-4296c4315727) to SuckerPunch(default)
However, when I send an http request to my user_controller, I don't receive any response before 3 seconds (which make me think that the job is not executed asynchronously), and the logger display this Enqueued MyJob (Job ID: e3d698eb-00d8-4849-9496-f01c53fc7217) to Inline(default)
It seems to use the inline (default?) adapter in controllers, which is not asynchronous.
ps : I'm using puma
as http server, and using sucker_punch without ActiveJob works fine
Upvotes: 2
Views: 880