mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Display human-friendly class and args for ActionMailer jobs
This commit is contained in:
parent
7686012b07
commit
ef99c7a9b1
2 changed files with 47 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue