问题
I currently have an ActiveJob that I've created and use Sidekiq to queue it. I'm wanting to debug the job, but for me to see any messages I program into it I have to check my log files. I feel like it would be more convenient to be able to see my puts
messages in my job in the Rails Console. When I run the perform_later
method though in rails console it just queues the job up and I never see the messages in console. Is there a way to make it where I will see them in the console?
回答1:
You can run a job with perform_now
.
For example...
class Foo < ActiveJob::Base
def perform(arg1)
puts "Hello #{arg1}"
end
end
Foo.perform_now('world')
回答2:
You can temporarily set your queue adapter to inline.
Right now your code in application.rb
will look something like this:
Rails.application.config.active_job.queue_adapter = :sidekiq
Just comment out the line
# Rails.application.config.active_job.queue_adapter = :sidekiq
This will run your job inline, and you should see the results in the console.
回答3:
There is a configuration line you can add in development.rb
require 'sidekiq/testing/inline'
This should enable inline testing for development.
来源:https://stackoverflow.com/questions/34519414/how-can-i-run-an-activejob-in-rails-console-for-debugging