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

Rails - how to use ActionDispatch::Integration::Session in ActiveJob

在 Rails' 控制台中 app 被定义为

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

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

class MyJob < ActiveJob::Base
  queue_as :low

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

如果我调用 MyJob.perform_now 我得到

NameError: undefined local variable or method `app' for

如何在 Rails' ActiveJob 中使用 app

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