2

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_laterin 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

Jérôme Boé
  • 2,752
  • 4
  • 21
  • 32
  • Have you checked your development.rb file? If there is a config option saying `config.active_job.queue_adapter = :inline` it might overwrite whatever you put in your initializer. – Jan Bussieck May 18 '16 at 14:21
  • This line is not present – Jérôme Boé May 18 '16 at 14:27
  • This is another stupid guess, but did you restart your rails server so the initializer could be loaded? – Jan Bussieck May 18 '16 at 14:32
  • 3
    Yes I did it multiple times. However, putting `config.active_job.queue_adapter = :sucker_punch` in application.rb makes it work. – Jérôme Boé May 18 '16 at 14:33
  • This must be the answer, if anyone has an idea, don't hesitate. – Jérôme Boé May 18 '16 at 14:44
  • I had exactly the same issue with sidekiq rather than sucker_punch. Using `Rails.application.config.active_job.queue_adapter = :sidekiq` or `My::Application.config.active_job.queue_adapter = :sidekiq` both failed. The only solution was to put `config.active_job.queue_adapter = :sidekiq` directly into the application.rb file. – Steve Smith Jan 25 '18 at 18:03

0 Answers0