Skip to content
Permalink
Browse files

Merge pull request #2465 from ekylibre/feature/job-info-rake-tasks

Added some tasks to get job infos from sidekiq
  • Loading branch information...
Aquaj committed Apr 2, 2019
2 parents 233bed6 + 63a5917 commit b0e96d26e998840ea7a04428425330d922a2f902
Showing with 67 additions and 0 deletions.
  1. +67 −0 lib/tasks/job.rake
  2. 0 lib/tasks/jobs.rake
@@ -10,6 +10,73 @@ namespace :job do
Sidekiq::ScheduledSet.new.clear
end

task running: :environment do
next false if Sidekiq::Stats.new.enqueued.zero?
job_class = ENV['JOB_CLASS']
job_tenant = ENV['TENANT']
running = false
Sidekiq::Queue.all.each do |queue|
jobs = queue.entries.select do |entry|
(!job_class || entry.item['args'].first['job_class'] == job_class) &&
(!job_tenant || entry.item['apartment'] == job_tenant)
end
running ||= jobs.any?

puts "\nMatching running jobs:" if jobs.any?
jobs.sort_by(&:at).each do |entry|
job = entry.item['args'].first['job_class']
puts " - #{job} on #{entry.item['apartment']} on queue #{queue.name}"
end
end
running
end

task done: :environment do
job_class = ENV['JOB_CLASS']
job_tenant = ENV['TENANT']
Sidekiq::DeadSet.include Enumerable
jobs = Sidekiq::DeadSet.new.select do |entry|
(!job_class || entry.item['args'].first['job_class'] == job_class) &&
(!job_tenant || entry.item['apartment'] == job_tenant)
end
puts "\nMatching jobs done:" if jobs.any?
jobs.sort_by(&:at).each do |entry|
job = entry.item['args'].first['job_class']
print " - #{job} on #{entry.item['apartment']}\n — Finished at #{entry.at}"
if entry.error?
error_class = entry.item["error_class"]
error_message = entry.item["error_message"]
puts " with error \"#{error_class}: #{error_message}\""
else
puts " without errors"
end
end.any?
end

desc "Displays all matching errored jobs"
task errored: :environment do
job_class = ENV['JOB_CLASS']
job_tenant = ENV['TENANT']
Sidekiq::DeadSet.include Enumerable
jobs = Sidekiq::DeadSet.new.select do |entry|
(!job_class || entry.item['args'].first['job_class'] == job_class) &&
(!job_tenant || entry.item['apartment'] == job_tenant) &&
entry.error?
end

puts "\nMatching errored jobs:" if jobs.any?
jobs.sort_by(&:at).each do |entry|
job = entry.item['args'].first['job_class']
error_class = entry.item["error_class"]
error_message = entry.item["error_message"]
print " - #{job} on #{entry.item['apartment']}\n — Finished at #{entry.at}"
puts " with error \"#{error_class}: #{error_message}\""
end.any?
end

desc "Displays all infos available for matching job (JOB_CLASS/TENANT)"
task job_status: [:running, :done]

task status: :environment do
puts 'Queues:'
Sidekiq::Queue.all.each do |queue|
No changes.

0 comments on commit b0e96d2

Please sign in to comment.
You can’t perform that action at this time.