Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly process ActiveJob payloads #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/resque_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions test/resque_web_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
29 changes: 29 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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