diff --git a/Gemfile b/Gemfile index 9e5a801..e34d20b 100644 --- a/Gemfile +++ b/Gemfile @@ -7,4 +7,5 @@ group :test do gem 'json' gem 'timecop' gem 'rack-test' + gem 'activejob', '5.2.3' end diff --git a/lib/resque_cleaner.rb b/lib/resque_cleaner.rb index 4a8148b..57d1298 100644 --- a/lib/resque_cleaner.rb +++ b/lib/resque_cleaner.rb @@ -52,7 +52,7 @@ def stats_by_date(&block) def stats_by_class(&block) jobs, stats = select(&block), {} jobs.each do |job| - klass = job["payload"] && job["payload"]["class"] ? job["payload"]["class"] : "UNKNOWN" + klass = job.klass stats[klass] ||= 0 stats[klass] += 1 end @@ -125,6 +125,7 @@ def requeue(clear_after_requeue=false, options={}, &block) value = redis.lindex(:failed, index) redis.multi do + # no change needed to support ActiveJob Job.create(queue||job['queue'], job['payload']['class'], *job['payload']['args']) if clear_after_requeue @@ -178,13 +179,18 @@ def after?(time) Time.parse(self['failed_at']) >= time end + # Returns true job name - incl wrapped ActiveJobs + def klass + payload_klass = self.dig("payload", "class") + if payload_klass == "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper" + payload_klass = self.dig("payload", "args").first.try :[], "job_class" + end + payload_klass || 'UNKNOWN' + end + # Returns true if the class of the job matches. Otherwise returns false. def klass?(klass_or_name) - if self["payload"] && self["payload"]["class"] - self["payload"]["class"] == klass_or_name.to_s - else - klass_or_name=="UNKNOWN" - end + self.klass == klass_or_name.to_s end # Returns true if the exception raised by the failed job matches. Otherwise returns false. diff --git a/lib/resque_cleaner/server.rb b/lib/resque_cleaner/server.rb index 855b485..a132a5f 100644 --- a/lib/resque_cleaner/server.rb +++ b/lib/resque_cleaner/server.rb @@ -118,7 +118,7 @@ def text_filter(id, name, value) @total = Hash.new(0) @jobs.each do |job| payload = job["payload"] || {} - klass = payload["class"] || 'UNKNOWN' + klass = job.klass exception = job["exception"] || 'UNKNOWN' failed_at = Time.parse job["failed_at"] @stats[:klass][klass] ||= Hash.new(0) diff --git a/lib/resque_cleaner/server/views/cleaner_list.erb b/lib/resque_cleaner/server/views/cleaner_list.erb index f38eaa8..4c056c1 100644 --- a/lib/resque_cleaner/server/views/cleaner_list.erb +++ b/lib/resque_cleaner/server/views/cleaner_list.erb @@ -89,7 +89,7 @@ <% end %>
<%= job['payload'] ? job['payload']['class'] : 'nil' %>
<%= job.klass %>
<%=h job['payload'] ? show_job_args(job['payload']['args']) : 'nil' %>