diff --git a/lib/sidekiq/api.rb b/lib/sidekiq/api.rb index 1991a386..66b313ce 100644 --- a/lib/sidekiq/api.rb +++ b/lib/sidekiq/api.rb @@ -283,7 +283,13 @@ module Sidekiq "#{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 @@ -297,7 +303,13 @@ module Sidekiq 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 diff --git a/test/test_api.rb b/test/test_api.rb index f71b2b0d..0c2b7ae1 100644 --- a/test/test_api.rb +++ b/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 @@ -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 @@ -203,6 +220,22 @@ class TestApi < Sidekiq::Test 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)