From 0551a76b1498f0f6b19c283fe788e0dc7e84320f Mon Sep 17 00:00:00 2001 From: h3nnn4n Date: Fri, 23 Oct 2020 09:42:32 -0300 Subject: [PATCH] Properly format ActiveJob payloads --- lib/resque_cleaner.rb | 7 +++++++ test/resque_web_test.rb | 7 +++++++ test/test_helper.rb | 29 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/lib/resque_cleaner.rb b/lib/resque_cleaner.rb index 4a8148b..4dbc6e7 100644 --- a/lib/resque_cleaner.rb +++ b/lib/resque_cleaner.rb @@ -251,6 +251,13 @@ def all(index=0,count=1) jobs = [] unless jobs jobs = [jobs] unless jobs.is_a?(Array) jobs.each{|j| j.extend FailedJobEx} + + # ActiveJob compatibility layer + jobs.each do |job| + next unless job.dig("payload", "class") == "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper" + job["payload"]["class"] = job.dig("payload", "args", 0, "job_class") + job["payload"]["args"] = job.dig("payload", "args", 0, "arguments") + end jobs end diff --git a/test/resque_web_test.rb b/test/resque_web_test.rb index f98d280..7329525 100644 --- a/test/resque_web_test.rb +++ b/test/resque_web_test.rb @@ -42,6 +42,13 @@ def setup_some_failed_jobs assert last_response.ok?, last_response.errors end + it '#cleaner_list shows ActiveJob failed jobs properly formated' do + add_activejob_failure + + get "/cleaner_list", :c => "ActiveJobGoodJob" + assert last_response.body.include?("ActiveJobGoodJob") + end + it '#cleaner_list shows the failed jobs' do get "/cleaner_list" assert last_response.body.include?('BadJob') diff --git a/test/test_helper.rb b/test/test_helper.rb index 698ac82..5f9c727 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -129,3 +129,32 @@ def add_empty_payload_failure data = Resque.encode(data) Resque.redis.rpush(:failed, data) end + +def add_activejob_failure + data = { + :failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S %Z"), + :payload => { + :class => "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper", + :args => [ + :job_class => "ActiveJobGoodJob", + :job_id => "0bc036ab-32c0-4ad0-9138-abdfb06658c4", + :provider_job_id => nil, + :queue_name => "download_scrape_job", + :priority => nil, + :arguments => [:good_job], + :executions => 0, + :exception_executions => {}, + :locale => "en", + :timezone => "UTC", + :enqueued_at => "2020-10-13T16:37:18Z" + ] + }, + :exception => "Resque::DirtyExit", + :error => "Resque::DirtyExit", + :backtrace => [], + :worker => "worker", + :queue => "queue" + } + data = Resque.encode(data) + Resque.redis.rpush(:failed, data) +end