2

In Rails' console app is defined as

[1] pry(main)> app
=> #<ActionDispatch::Integration::Session:0x000000189028e8

Now, I have a simple job like:

class MyJob < ActiveJob::Base
  queue_as :low

  def perform
    app.get('/my/path', nil, {'Accept-Language' => "it"})
  end
end

If I call MyJob.perform_now I get

NameError: undefined local variable or method `app' for

How can I use app in a Rails' ActiveJob?

davideghz
  • 3,596
  • 5
  • 26
  • 50
  • What will be a goal of such job? It looks very weird... I take into account a possibility, that you move in wrong direction – AntonTkachov Nov 08 '17 at 18:14
  • are you just trying to get a rendered response of the page? to Save it to a static file or something? If you are on rails 5 there is easier way to do it than using a app.get – Shaunak Nov 08 '17 at 18:20
  • 1
    I need to call a controller's method, basically to trigger some cache-related-stuffs – davideghz Nov 08 '17 at 18:21

1 Answers1

5
class MyJob < ActiveJob::Base
  queue_as :low

  def perform
    app = ActionDispatch::Integration::Session.new(Rails.application)
    app.get('/my/path', nil, {'Accept-Language' => "it"})
  end
end
AntonTkachov
  • 1,784
  • 1
  • 10
  • 29