Rails - 如何在 ActiveJob 中使用 ActionDispatch::Integration::Session

dav*_*ghz 2 ruby-on-rails actiondispatch rails-activejob

在 Rails 的控制台app中定义为

[1] pry(main)> app
=> #<ActionDispatch::Integration::Session:0x000000189028e8
Run Code Online (Sandbox Code Playgroud)

现在,我有一份简单的工作,例如:

class MyJob < ActiveJob::Base
  queue_as :low

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

如果我打电话MyJob.perform_now我得到

NameError:未定义的局部变量或方法“app”

如何app在 Rails 的 ActiveJob 中使用?

Ant*_*hov 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
Run Code Online (Sandbox Code Playgroud)