Skip to content

[sidekiq] How to list Sidekiq jobs in the Rails console

Published: at 09:03 AM (1 min read)

List all scheduled jobs in Sidekiq

scheduled_jobs = Sidekiq::ScheduledSet.new

scheduled_jobs.each do |job|
  puts "Class: #{job.klass}, Arguments: #{job.args.inspect}, Job ID: #{job.jid}, Enqueue at: #{Time.at(job.at).to_s}"
end

List all enqueued jobs in Sidekiq

queues = Sidekiq::Queue.all

queues.each do |queue|
  queue.each do |job|
    puts "Class: #{job.klass}, Arguments: #{job.args.inspect}, Job ID: #{job.jid}"
  end
end

List all running jobs in Sidekiq

workers = Sidekiq::Workers.new

workers.each do |process_id, thread_id, work|
  puts "Process ID: #{process_id}, Thread ID: #{thread_id}, Job: #{work['payload']['class']}, Args: #{work['payload']['args'].inspect}"
end

Previous Post
[HTML] Referrer-Policy 是什麼?
Next Post
[rails] 在 Rails console 顯示 debug 訊息(如 SQL)