Skip to content

Commit

Permalink
Display human-friendly class and args for ActionMailer jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
dreyks committed Dec 14, 2015
1 parent 7686012 commit ef99c7a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/sidekiq/api.rb
Expand Up @@ -283,7 +283,13 @@ def display_class
"#{target}.#{method}"
end
when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
@item['wrapped'] || args[0]
job_class = @item['wrapped'] || args[0]
if 'ActionMailer::DeliveryJob' == job_class
# MailerClass#mailer_method
args[0]['arguments'][0..1].join('#')
else
job_class
end
else
klass
end
Expand All @@ -297,7 +303,13 @@ def display_args
arg
end
when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
@item['wrapped'] ? args[0]["arguments"] : []
job_args = @item['wrapped'] ? args[0]["arguments"] : []
if 'ActionMailer::DeliveryJob' == (@item['wrapped'] || args[0])
# remove MailerClass, mailer_method and 'deliver_now'
job_args.drop(3)
else
job_args
end
else
args
end
Expand Down
33 changes: 33 additions & 0 deletions test/test_api.rb
@@ -1,5 +1,7 @@
require_relative 'helper'
require 'sidekiq/api'
require 'active_job'
require 'action_mailer'

class TestApi < Sidekiq::Test
describe 'api' do
Expand Down Expand Up @@ -168,6 +170,21 @@ class TestApi < Sidekiq::Test
assert_equal 0, q.latency
end

before do
ActiveJob::Base.queue_adapter = :sidekiq
ActiveJob::Base.logger = nil

class ApiMailer < ActionMailer::Base
def test_email(*)
end
end

class ApiJob < ActiveJob::Base
def perform(*)
end
end
end

class ApiWorker
include Sidekiq::Worker
end
Expand Down Expand Up @@ -203,6 +220,22 @@ class ApiWorker
assert_equal [1,2,3], x.display_args
end

it 'unwraps ActiveJob jobs' do
ApiJob.perform_later(1, 2, 3)
q = Sidekiq::Queue.new
x = q.first
assert_equal "TestApi::ApiJob", x.display_class
assert_equal [1,2,3], x.display_args
end

it 'unwraps ActionMailer jobs' do
ApiMailer.test_email(1, 2, 3).deliver_later
q = Sidekiq::Queue.new('mailers')
x = q.first
assert_equal "TestApi::ApiMailer#test_email", x.display_class
assert_equal [1,2,3], x.display_args
end

it 'has no enqueued_at time for jobs enqueued in the future' do
job_id = ApiWorker.perform_in(100, 1, 'foo')
job = Sidekiq::ScheduledSet.new.find_job(job_id)
Expand Down

0 comments on commit ef99c7a

Please sign in to comment.